在Android的开发中可能会用到RadioButton和CheckBox这两个控件,如果你对MFC开发熟悉的话,相信对这两个控件并不陌生,它们的形状也都是一样的,RadioButton是圆形单选按钮,既然是单选按钮,就需要规划好Group的概念,即在那一组中只能选择一个选项。而CheckBox是正方形的控件,即多选按钮,没有组的概念,一个控件就是一个单独的对象,互相不干扰,下面请看实现的具体例子的截图:

具体的实现代码如下:

  1. public class MainActivity extends Activity {  

  2.    private RadioGroup radioGroup;  

  3.    private RadioButton radioButton1;  

  4.    private RadioButton radioButton2;  

  5.    private CheckBox checkBox1;  

  6.    private CheckBox checkBox2;  

  7.    private CheckBox checkBox3;  

  8.    private Button button;  

  9.    String string="";  

  10.  

  11.    @Override  

  12.    protected void onCreate(Bundle savedInstanceState) {  

  13.        super.onCreate(savedInstanceState);  

  14.        setContentView(R.layout.activity_main);  

  15.        radioGroup=(RadioGroup)findViewById(R.id.radiogroup);  

  16.        radioButton1=(RadioButton)findViewById(R.id.radiobutton1);  

  17.        radioButton2=(RadioButton)findViewById(R.id.radiobutton2);  

  18.        checkBox1=(CheckBox)findViewById(R.id.checkbox1);  

  19.        checkBox2=(CheckB