728x90
반응형
https://developer.android.com/guide/topics/ui/binding?hl=ko
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/Text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="180dp"
android:layout_marginBottom="19dp"
android:text="선택을 시작하겠습니까?"
android:textColor="#ff0000"
android:textSize="20dp"
app:layout_constraintBottom_toTopOf="@+id/checkBox"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<CheckBox
android:id="@+id/checkBox"
android:layout_width="116dp"
android:layout_height="0dp"
android:layout_marginBottom="14dp"
android:text="시작함!"
app:layout_constraintBottom_toTopOf="@+id/textView2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/Text1" />
<RadioGroup
android:id="@+id/Rgroup1"
android:layout_width="181dp"
android:layout_height="0dp"
android:layout_marginBottom="10dp"
android:orientation="horizontal"
android:visibility="invisible"
app:layout_constraintBottom_toTopOf="@+id/button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView2">
<RadioButton
android:id="@+id/RdoDog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="개" />
<RadioButton
android:id="@+id/RdoCat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="고양이" />
<RadioButton
android:id="@+id/RdoRabbit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="토끼" />
</RadioGroup>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="14dp"
android:layout_weight="1"
android:text="좋아하는 애완동물은?"
android:visibility="invisible"
app:layout_constraintBottom_toTopOf="@+id/Rgroup1"
app:layout_constraintStart_toStartOf="@+id/Rgroup1"
app:layout_constraintTop_toBottomOf="@+id/checkBox" />
<Button
android:id="@+id/BtnOk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="329dp"
android:text="선택완료"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/Rgroup1" />
<ImageView
android:id="@+id/ImgPat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="36dp"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:srcCompat="@drawable/dog" />
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity
package com.cookandroidappstudy.mypetphotoappexample;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
TextView text1, text2;
CheckBox chkAgree;
RadioGroup rGroup1;
RadioButton rdoDog, rdoCat, rdoRabbit;
Button btnOk;
ImageView imgPet;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setTitle("애완동물 사진 보기");
text1 = (TextView) findViewById(R.id.Text1); // 선택을 시작하시겠습니까?
chkAgree = (CheckBox)findViewById(R.id.checkBox); // 체크 박스
text2 = (TextView)findViewById(R.id.TextView); // 좋아하는 동물은?
rGroup1 = (RadioGroup)findViewById(R.id.Rgroup1); // 라디오 그룹
rdoDog = (RadioButton)findViewById(R.id.RdoDog); // 라디오버튼 : Dog
rdoCat = (RadioButton)findViewById(R.id.RdoCat); // 라디오버튼 : Cat
rdoRabbit = (RadioButton)findViewById(R.id.RdoRabbit); // 라디오버튼 : Rabbit
btnOk = (Button)findViewById(R.id.BtnOk); // 선택 완료 버튼
imgPet = (ImageView)findViewById(R.id.ImgPat); // 선택된 이미지가 보여지는 이미지뷰 영역
chkAgree.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
if(chkAgree.isChecked()==true){
text2.setVisibility(View.VISIBLE);
rGroup1.setVisibility(View.VISIBLE);
btnOk.setVisibility(View.VISIBLE);
imgPet.setVisibility(View.VISIBLE);
}else{
text2.setVisibility(View.INVISIBLE);
rGroup1.setVisibility(View.INVISIBLE);
btnOk.setVisibility(View.INVISIBLE);
imgPet.setVisibility(View.INVISIBLE);
}
}
});
btnOk.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
switch (rGroup1.getCheckedRadioButtonId()){
case R.id.RdoDog:
imgPet.setImageResource(R.drawable.dog);
break;
case R.id.RdoCat:
imgPet.setImageResource(R.drawable.cat);
break;
case R.id.RdoRabbit:
imgPet.setImageResource(R.drawable.rabbit);
break;
default:
Toast.makeText(getApplicationContext(), "동물 먼저 선택하세요!", Toast.LENGTH_SHORT).show();
}
}
});
}
}
728x90
반응형
'☭DEVELOPER > #2 웹개발(자바기반 풀스택)' 카테고리의 다른 글
[BACKEND]SPRING PG 카드결제 연동개발2 (0) | 2023.11.02 |
---|---|
[BACKEND]SPRING PG 카드 결제 연동 개발 (0) | 2023.11.02 |
[BACKEND]안드로이드 앱 apk 파일 배포 (0) | 2023.10.26 |
[FRONTEND]React AOS 라이브러리 적용 및 활용 (0) | 2023.10.25 |
[FRONTEND]리액트 Event Handling (0) | 2023.10.24 |