I\'m writing an Activity
in android where I have two radio buttons under a RadioGroup. One of them is checked by default. But I can\'t trigger the event in
Try this Code.
Declare this code in your onCreate method.
RadioGroup radioGroup = (RadioGroup) findViewById(R.id.radiogroup);
radioGroup.clearCheck();
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
RadioButton rb = (RadioButton) group.findViewById(checkedId);
if (null != rb && checkedId > -1) {
// checkedId is the RadioButton selected
switch (checkedId) {
case R.id.one:
// Do Something
break;
case R.id.two:
// Do Something
break;
case R.id.three:
// Do Something
break;
}
}
}
});
Hope this helps.