์ํ๋ ๊ณ ์์ด ์ฌ์ง์ ์ถ๋ ฅํ๋ ์ฑ ๋ง๋ค๊ธฐ
'์์ํจ'์ ์ฒดํฌํ๋ฉด ์ํ๋ ์ฌ์ง ๋ฒํธ ์ค ํ๋๋ฅผ ์ ํํ๋ผ๋ ๋ด์ฉ์ด ๋์ค๊ณ , ์ ํ ํ์ <์ ํ์๋ฃ> ๋ฒํผ์ ๋๋ฅด๋ฉด ํด๋น ๊ณ ์์ด์ ์ด๋ฏธ์ง๊ฐ ๋ํ๋๋ค.
์ฌ์ง์ ๋ณต์ฌ ํ์ฌ [res]-[drawable]์ ๋ถ์ด ๋ฃ๊ธฐ ํด์ค๋ค.
activity_main.xml ์ฝ๋
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:id="@+id/Text1"
android:text="์ ํ์ ์์ํ๊ฒ ์ต๋๊น?"
android:layout_marginLeft="30dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<CheckBox
android:id="@+id/chkAgree"
android:text="์์ํจ"
android:layout_marginLeft="30dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView android:id="@+id/Text2"
android:text="๋น์ ์ ๋ฌ์ด ๋ฒ ์คํธ ํฝ์?"
android:visibility="invisible"
android:layout_marginLeft="30dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<RadioGroup
android:id="@+id/Rgroup1"
android:visibility="invisible"
android:layout_marginLeft="30dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RadioButton
android:id="@+id/RdoDal1"
android:text="๋ฌ์ด์ฌ์ง1"
android:layout_marginLeft="30dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<RadioButton
android:id="@+id/RdoDal2"
android:text="๋ฌ์ด์ฌ์ง2"
android:layout_marginLeft="30dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<RadioButton
android:id="@+id/RdoDal3"
android:text="๋ฌ์ด์ฌ์ง3"
android:layout_marginLeft="30dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RadioGroup>
<Button
android:id="@+id/BtnOk"
android:text="์ ํ์๋ฃ"
android:visibility="invisible"
android:layout_marginLeft="30dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<ImageView
android:id="@+id/ImgDal"
android:visibility="invisible"
android:layout_marginLeft="30dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
|
cs |
๋งจ์ TextView ์ CheckBox๋ฅผ ์ ์ธํ๊ณ ๋๋จธ์ง ์์ ฏ์ visibility ์์ฑ์ invisible๋ก ์ง์ ํ๋ค.
RadioGroup์์ visibility ์์ฑ์ ์ค์ ํ๋ฉด ๊ทธ ์์ RadioButton๋ค์ ์์ฑ์ ์ค์ ํ์ง ์์๋ ๋๋ค.
๋ผ๋์ค ๊ทธ๋ฃน์ผ๋ก ๋ผ๋์ค ๋ฒํผ 1,2,3์ ๋ฌถ์ด์ ํด๋น ๋ผ๋์ค ๊ทธ๋ฃน ์ฌ์ด์์๋ง ์ค๋ณต์ด ๋์ง ์๊ฒ ํด์ค๋ค.
์ ํํจ์ ์ ํํด์ผ ์ฌ์ง์ ๊ณ ๋ฅผ ์ ์๊ฒ ํ๊ธฐ ์ํด์ ์ ํํจ์ด๋ผ๋ ์ฒดํฌ๋ฐ์ค๋ ๋ง๋ค์ด ์ค๋ค.
MainActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
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 rdoDal1, rdoDal2, rdoDal3;
Button btnOk;
ImageView imgDal;
@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.chkAgree);
text2= (TextView) findViewById(R.id.Text2);
rGroup1=(RadioGroup) findViewById(R.id.Rgroup1);
rdoDal1=(RadioButton) findViewById(R.id.RdoDal1);
rdoDal2=(RadioButton) findViewById(R.id.RdoDal2);
rdoDal3=(RadioButton) findViewById(R.id.RdoDal3);
btnOk= (Button) findViewById(R.id.BtnOk);
imgDal= (ImageView) findViewById(R.id.ImgDal);
chkAgree.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(chkAgree.isChecked()==true){
text2.setVisibility(android.view.View.VISIBLE);
rGroup1.setVisibility(android.view.View.VISIBLE);
btnOk.setVisibility(android.view.View.VISIBLE);
imgDal.setVisibility(android.view.View.VISIBLE);
}else{
text2.setVisibility(android.view.View.INVISIBLE);
rGroup1.setVisibility(android.view.View.INVISIBLE);
btnOk.setVisibility(android.view.View.INVISIBLE);
imgDal.setVisibility(android.view.View.INVISIBLE);
}
}
});
btnOk.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
switch (rGroup1.getCheckedRadioButtonId()){
case R.id.RdoDal1:
imgDal.setImageResource(R.drawable.dal1);
break;
case R.id.RdoDal2:
imgDal.setImageResource(R.drawable.dal2);
break;
case R.id.RdoDal3:
imgDal.setImageResource(R.drawable.dal3);
break;
default:
Toast.makeText(getApplicationContext(),
"๋ฌ์ด ์ฌ์ง๋ฒํธ๋ฅผ ์ ํํ์ธ์", Toast.LENGTH_SHORT).show();
}
}
});
}
}
|
cs |
14ํ~19ํ : ์ ํด๋์ค์์ ์ธ ์ ์ญ๋ณ์๋ค์ ์ ์ธํด ์ค๋ค.
27ํ~37ํ : ๊ฐ ์์ ฏ์ ๋ณ์์ ๋์ ํ๋ค. XML ์์ ์ ํด์ค id๋ก ๋ถ๋ฌ์ฌ ์ ์๋ค.
39ํ : '์์ํจ' ์ฒดํฌ๋ฐ์ค๋ฅผ ์ฒดํฌ/์ธ์ฒดํฌํ ๋๋ง๋ค ๋์ํ๋ ๋ฆฌ์ค๋๋ฅผ ์ค์ ํ๋ค.
์ปดํ์ด๋ ๋ฒํผ์ด๊ธฐ ๋๋ฌธ์ View.OnCheckedChangeListener()๊ฐ ์๋๋ผ CompoundButton.OnCheckedChangeListener() ๋ฆฌ์ค๋์ด๋ค.
42ํ : ์ฒดํฌ๋ฐ์ค๊ฐ ์ฒดํฌ ๋์ด ์๋ ์กฐ๊ฑด์ผ๋๋ฅผ ๋งํ๋ค.
43ํ~46ํ : ์จ๊ฒจ์ ธ ์๋ ๋ชจ๋ ์์ ฏ์ ๋ณด์ด๋๋ก ํ๋ค.
47ํ ~ 51ํ : ์ฒดํฌ๊ฐ๊บผ์ง๋ฉด ์์ ฏ๋ค์ ์จ๊ธด๋ค.
55ํ : ์ ํ ์๋ฃ๋ฅผ ํด๋ฆญํ๋ฉด ๋์ํ๋ ๋ฆฌ์ค๋๋ฅผ ์ค์ ํ๋ค.
59ํ~70ํ : switch()~ case ๋ฌธ์ผ๋ก ๋ค์ค ๋ถ๊ธฐํ๋ค. getCheckedRadioButtonId()๋ ํ์ฌ ๋ผ๋์ค ๊ทธ๋ฃน์์ ์ ํ๋ ๋ผ๋์ค ๋ฒํผ์ ์์ด๋๋ฅผ ๋ฐํํ๋ค.
๊ฐ ๋ผ๋์ค ๋ฒํผ์ ๋ง๋ ์ฌ์ง์ ๋ณด์ฌ์ค๋ค.
68~70ํ : ๋ผ๋์ค๋ฒํผ์ค์์ ์๋ฌด๊ฒ๋ ์ ํ๋์ง ์์๋ค๋ฉด ํ ์คํธ ๋ฉ์์ง๋ฅผ ๋ณด์ฌ์ค๋ค.
์คํ ๊ฒฐ๊ณผ:
์ฒ์์ ์๋ฎฌ๋ ์ดํฐ๋ ๋์๊ฐ๋๋ฐ ์ดํ์ด ์คํ๋์ง ์์์ ๋ช์๊ฐ์ ํด๊ฒฐํ๋๋ผ ๊ณ ์ํ๋ค..........
๋ฌธ์ ์ ์์ธ์ AVD์ค์นํ ๋ ์ ์ฅ์๊ฐ 800mb๊ฐ ๋ํดํธ๋ก ์ ํด์ ธ ์์ด ์ฉ๋์ด ๋ถ์กฑํด์ ๊ทธ๋ฐ ๊ฒ์ด์๋ค.
๋๊ธ