This problem can be solved using the following
RadioGroup rg = (RadioGroup) findViewById(R.id.radioGroup1);
rg.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
@Override
public void onCheckedChanged(RadioGroup group, int checkedId)
{
switch(checkedId)
{
case R.id.radio0:
// TODO Something
break;
case R.id.radio1:
// TODO Something
break;
case R.id.radio2:
// TODO Something
break;
}
}
});
Alternatively
You can use custom ids rather than default one
RadioGroup rg = (RadioGroup) findViewById(R.id.radioGroup1);
rg.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
@Override
public void onCheckedChanged(RadioGroup group, int checkedId)
{
switch(checkedId)
{
case R.id.male:
// TODO Something
break;
case R.id.female:
// TODO Something
break;
case R.id.other:
// TODO Something
break;
}
}
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…