好吧~前几天玩多了。我承认!今天又看了一集。其实多学点还是蛮爽的。至少心里爽
今天的主要内容
1、RadioGroup和RadioButton的使用方法
(1)RadioGroup、RadioButton是双生的。一个组里面可以包含多个RadioButton。这个在xxx.xml布局文件中要进行设置
(2)给RadioGroup加监听器,RadioGroup的监听器和前面Button的监听器不同。RadioGroup用的是setOnCheckedChangeListener,而Button用的是setOnClickListener。从字面上就可以看出区别,一个是选择一个是按下
下面是个哦RadioButton绑定监听器的代码
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
if(female.getId() == checkedId){
Toast.makeText(Controlor2.this, "female", Toast.LENGTH_SHORT).show();
}
if(male.getId() == checkedId){
Toast.makeText(Controlor2.this, "male", Toast.LENGTH_SHORT).show();
}
}
});
(3)cheackBox在Xml里的布局方法与一般的TextView等控件类似,它添加监听器的方法与上述都不同,要注意
下面是监听器代码
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
if(isChecked){
Toast.makeText(Controlor2.this, "swim",Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(Controlor2.this, "do not like swim", Toast.LENGTH_LONG).show();
}
}
});
好了,今晚就到这里,明天再见!