Android开发--RadioButton和CheckBox控件的使用
在Android的开发中可能会用到RadioButton和CheckBox这两个控件,如果你对MFC开发熟悉的话,相信对这两个控件并不陌生,它们的形状也都是一样的,RadioButton是圆形单选按钮,既然是单选按钮,就需要规划好Group的概念,即在那一组中只能选择一个选项。而CheckBox是正方形的控件,即多选按钮,没有组的概念,一个控件就是一个单独的对象,互相不干扰,下面请看实现的具体例子的截图:
具体的实现代码如下:
public class MainActivity extends Activity {
private RadioGroup radioGroup;
private RadioButton radioButton1;
private RadioButton radioButton2;
private CheckBox checkBox1;
private CheckBox checkBox2;
private CheckBox checkBox3;
private Button button;
String string="";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
radioGroup=(RadioGroup)findViewById(R.id.radiogroup);
radioButton1=(RadioButton)findViewById(R.id.radiobutton1);
radioButton2=(RadioButton)findViewById(R.id.radiobutton2);
checkBox1=(CheckBox)findViewById(R.id.checkbox1);
checkBox2=(CheckB