Android-RadioButton&RadioGroup
一 定义
符合单选框,两个需要配合使用
二 事件机制
private void showRadioButton()
{
mRadioGroup = (RadioGroup)findViewById(R.id.radioGroup1);
mRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener()//事件监听器
{
@Override
public void onCheckedChanged(RadioGroup arg0, int arg1)
{
// TODO Auto-generated method stub
switch (arg1)//一般使用switch语句作为业务逻辑
{
case R.id.radio0:
Log.i("chengzhi log", "Radio 0");//业务逻辑
break;
case R.id.radio1:
Log.i("chengzhi log", "Radio 1");;//业务逻辑
break;
case R.id.radio2:
Log.i("chengzhi log", "Radio 2");;//业务逻辑
break;
default:
Log.i("chengzhi log", "please select!");
break;
}
}
});
}
时间: 2024-11-05 20:55:27