1

I have two radio buttons in a radio group and when i select any of the radio button and try to get the boolean value using the isselected method then i always get the false value. Why this is happening.Please help me.

Sahil
  • 96
  • 11

4 Answers4

2

I had the same problem too, isSelected method didn't work. The isChecked method worked for me:

if( myRadioButton.isChecked() ){ // do stuff } else { // do other stuff }

0

Use this:

radioButton.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        public void onCheckedChanged(CompoundButton btn, boolean isCheck) {

            //handle the boolean flag here. 
              if(isCheck==true)
                     //Do something

            else 
                //do something else

        }
    });

source: link

Community
  • 1
  • 1
SacreDeveloper
  • 1,253
  • 1
  • 9
  • 16
0

Maybe this will help

int radioButtonID = radioButtonGroup.getCheckedRadioButtonId();
View radioButton = radioButtonGroup.findViewById(radioButtonID);

Then use the radioButton to perform whatever task you want.

Source : Link

Community
  • 1
  • 1
Codester
  • 193
  • 6
0

Use this:

int selectedRbBtn = radiogroup.getCheckedRadioButtonId();

If it returns -1 then nothing was selected...

Armfoot
  • 4,663
  • 5
  • 45
  • 60
KeLLaX
  • 1