//根据ID找到RadioGroup实例
RadioGroup group = (RadioGroup) findViewById(R.id.radioGroup);
//绑定一个匿名监听器
group.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup arg0, int arg1) {
//获取变更后的选中项的ID
int radioButtonId = arg0.getCheckedRadioButtonId();
switch(radioButtonId){
case R.id.radiobtn1:
//todo what you want
break;
case R.id.radiobtn2:
//todo what you want
break;
}
}
});
xml文件中RadioButton必须放在 RadioGroup中。