Adsense Ad

Thursday 24 August 2017

How to check if a radiobutton is checked in a radiogroup in Android?


You can take the RadioGroup id which contains 3 radio buttons.
  RadioGroup radiogrp = (RadioGroup) findViewById(R.id.RadioGroup);
  int id = radiogrp.getCheckedRadioButtonId();
This will return the identifier of the selected radio button in this group. Upon empty selection, the returned value is -1.
So you can put if condition and check whether the id == -1 than no radio button is selected.

if (id == -1)
{
  // no radio buttons are checked
}
else
{
  // one of the radio buttons is checked
}

1 comment:

Unknown said...

why is my unchecked id is "2131165322"?