1 |
package soo.ui.simple; |
---|
2 |
|
---|
3 |
import android.app.Activity; |
---|
4 |
import android.graphics.Color; |
---|
5 |
import android.os.Bundle; |
---|
6 |
import android.util.Log; |
---|
7 |
import android.view.View; |
---|
8 |
import android.view.View.OnClickListener; |
---|
9 |
import android.widget.EditText; |
---|
10 |
import android.widget.RadioButton; |
---|
11 |
import android.widget.RadioGroup; |
---|
12 |
import android.widget.RadioGroup.OnCheckedChangeListener; |
---|
13 |
|
---|
14 |
public class RadioButtonTest extends Activity { |
---|
15 |
/** Called when the activity is first created. */ |
---|
16 |
|
---|
17 |
RadioButton bt01=null; |
---|
18 |
RadioButton bt02=null; |
---|
19 |
RadioButton bt03=null; |
---|
20 |
RadioButton bt04=null; |
---|
21 |
RadioButton bt05=null; |
---|
22 |
|
---|
23 |
RadioGroup rg1=null; |
---|
24 |
RadioGroup rg2=null; |
---|
25 |
EditText et=null; |
---|
26 |
|
---|
27 |
@Override |
---|
28 |
public void onCreate(Bundle savedInstanceState) { |
---|
29 |
super.onCreate(savedInstanceState); |
---|
30 |
setContentView(R.layout.main); |
---|
31 |
|
---|
32 |
rg1 = (RadioGroup)findViewById(R.id.radioGroup01); |
---|
33 |
rg2 = (RadioGroup)findViewById(R.id.radioGroup02); |
---|
34 |
et = (EditText)findViewById(R.id.et); |
---|
35 |
|
---|
36 |
|
---|
37 |
rg1.setOnCheckedChangeListener(new A()); |
---|
38 |
rg2.setOnCheckedChangeListener(new A()); |
---|
39 |
/* |
---|
40 |
rg1.setOnCheckedChangeListener(new OnCheckedChangeListener() { |
---|
41 |
|
---|
42 |
@Override |
---|
43 |
public void onCheckedChanged(RadioGroup group, int checkedId) { |
---|
44 |
// TODO Auto-generated method stub |
---|
45 |
if(group == rg1){ |
---|
46 |
et.setText(new Integer(checkedId).toString()); |
---|
47 |
et.setTextColor(Color.BLUE); |
---|
48 |
}else{ |
---|
49 |
et.setText(new Integer(checkedId).toString()); |
---|
50 |
et.setTextColor(Color.RED); |
---|
51 |
} |
---|
52 |
} |
---|
53 |
}); |
---|
54 |
*/ |
---|
55 |
/* |
---|
56 |
bt01 = (RadioButton)findViewById(R.id.radioButton01); |
---|
57 |
bt02 = (RadioButton)findViewById(R.id.radioButton02); |
---|
58 |
bt03 = (RadioButton)findViewById(R.id.radioButton03); |
---|
59 |
bt04 = (RadioButton)findViewById(R.id.radioButton04); |
---|
60 |
bt05 = (RadioButton)findViewById(R.id.radioButton05); |
---|
61 |
|
---|
62 |
bt01.setOnClickListener(new A()); |
---|
63 |
bt02.setOnClickListener(new A()); |
---|
64 |
bt03.setOnClickListener(new A()); |
---|
65 |
bt04.setOnClickListener(new A()); |
---|
66 |
bt05.setOnClickListener(new A()); |
---|
67 |
*/ |
---|
68 |
} |
---|
69 |
/* |
---|
70 |
class A implements OnClickListener{ |
---|
71 |
@Override |
---|
72 |
public void onClick(View v) { |
---|
73 |
// TODO Auto-generated method stub |
---|
74 |
Log.d("radioTest", v.toString()); |
---|
75 |
} |
---|
76 |
} |
---|
77 |
*/ |
---|
78 |
|
---|
79 |
class A implements OnCheckedChangeListener{ |
---|
80 |
@Override |
---|
81 |
public void onCheckedChanged(RadioGroup group, int checkedId) { |
---|
82 |
// TODO Auto-generated method stub |
---|
83 |
RadioButton rb = (RadioButton)findViewById(checkedId); |
---|
84 |
et.setText(rb.getText()); |
---|
85 |
if(group == rg1){ |
---|
86 |
et.setTextColor(Color.BLUE); |
---|
87 |
}else{ |
---|
88 |
et.setTextColor(Color.RED); |
---|
89 |
} |
---|
90 |
} |
---|
91 |
} |
---|
92 |
} |
---|