radio group setOnCheckedChangeListener
RadioGroup yourRadioGroup = (RadioGroup) findViewById(R.id.radioGroup1);
yourRadioGroup.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;
}
}
});
Or, if you prefer:
yourRadioGroupName.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener()
{
@Override
public void onCheckedChanged(RadioGroup group, int checkedId)
{
int idRadioButtonChosen = yourRadioGroupName.getCheckedRadioButtonId();
if(idRadioButtonChosen > 0){
radioButtonChosen = (RadioButton) findViewById(idRadioButtonChosen);
textViewOnclick.setText(radioButtonChosen.getText());
}
}
});
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener()
{
public void onCheckedChanged(RadioGroup group, int checkedId) {
// checkedId is the RadioButton selected
RadioButton rb=(RadioButton)findViewById(checkedId);
Toast.makeText(getApplicationContext(), rb.getText(), Toast.LENGTH_SHORT).show();
}
});