RadioButton:
RadioButton要放在RadioGroup中,點擊切換產生的事件監聽是
比如性別
RadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener(){
@Override
public void onCheckedChanged(RadioGroup group, int checkedId){
if(femaleButton.getId() == checkedId){
Toast.makeText(Activity.this, "female", Toast.LENGTH_SHORT).show();
}else if(maleButton.getId() == checkedId){
}
});
CheckBox:
checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener(){
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked){
if(isChecked){
.....
}else{
.......
}
});