android RadioGroup的使用
创建一个MainActivity.java的主类
Xml代码
1. <?xml version="1.0" encoding="UTF-8"?>
2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3. android:layout_width="fill_parent"
4. android:layout_height="fill_parent"
5. android:orientation="vertical">
6. <TextView
7. android:id="@+id/radiobutton_textview"
8. android:layout_width="fill_parent"
9. android:layout_height="50dip"
10. android:textSize="18dip"
11. android:textStyle="bold"
12. android:background="@android:drawable/title_bar"
13. android:textAppearance="?android:attr/textAppearanceLarge"
14. android:gravity="center_vertical"
15. />
16. <RadioGroup
17. android:id="@+id/group"
18. android:layout_width="fill_parent"
19. android:layout_height="wrap_content"
20. android:orientation="vertical">
21. <RadioButton
22. android:id="@+id/button1"
23. android:layout_width="fill_parent"
24. android:layout_height="50dip"
25. android:textSize="20dip"
26. android:paddingLeft="30dip"
27. android:text="Android新手"
28. android:button="@null"
29. android:drawableRight="@android:drawable/btn_radio"/>
30. <View
31. android:layout_width="fill_parent"
32. android:layout_height="1px"
33. android:background="?android:attr/listDivider"
34. />
35. <RadioButton
36. android:id="@+id/button2"
37. android:layout_width="fill_parent"
38. android:layout_height="50dip"
39. android:textSize="20dip"
40. android:paddingLeft="30dip"
41. android:text="Android高手"
42. android:button="@null"
43. android:drawableRight="@android:drawable/btn_radio"/>
44. </RadioGroup>
45. </LinearLayout>
Xml代码
1.
Xml代码
1. <PRE class=java name="code">package endual.radio;
2.
3. import android.app.Activity;
4. import android.os.Bundle;
5. import android.widget.RadioButton;
6. import android.widget.RadioGroup;
7. import android.widget.RadioGroup.OnCheckedChangeListener;
8. import android.widget.TextView;
9.
10. public class MainActivity extends Activity {
11. private TextView textView;
12. private RadioGroup group;
13.
14. private RadioButton rb1 ;
15. private RadioButton rb2 ;
16. /** Called when the activity is first created. */
17. @Override
18. public void onCreate(Bundle savedInstanceState) {
19. super.onCreate(savedInstanceState);
20. setContentView(R.layout.main);
21.
22. textView = (TextView) findViewById(R.id.radiobutton_textview);
23. group = (RadioGroup) findViewById(R.id.group);
24.
25. this.rb1 = (RadioButton) this.findViewById(R.id.button1) ;
26. this.rb2 = (RadioButton) this.findViewById(R.id.button2) ;
27.
28.
29. // 单选按钮组监听事件
30. group.setOnCheckedChangeListener(new OnCheckedChangeListener() {
31.
32. @Override
33. public void onCheckedChanged(RadioGroup
补充:移动开发 , Android ,