Uncheck all RadioButton in a RadioButtonGroup

30,059

Solution 1

RadioGroup radioGroup = (RadioGroup)findViewById(R.id.radiogroup);
radioGroup.clearCheck();

Solution 2

use clearCheck() for clearing all checked radiobutton when acticity is started or resumed

 @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
 RadioGroup rg=(RadioGroup)findViewById(R.id.RG);
rg.clearCheck();
}
@Override
protected void onResume() {  
RadioGroup rg=(RadioGroup)findViewById(R.id.RG);
rg.clearCheck();  
super.onResume();  
    }  

Solution 3

use this

RadioButton spec1=findViewById(yourRadioGroup.getCheckedRadioButtonId());
        if (spec1.isChecked())
        {
            spec1.setChecked(false);
        }
Share:
30,059
Jayson Tamayo
Author by

Jayson Tamayo

Updated on July 09, 2022

Comments

  • Jayson Tamayo
    Jayson Tamayo almost 2 years

    What I wanted to achieve is this: Right after the activity starts, I want that no RadioButton is selected/checked.

    My problem is this: When the activity starts, the first RadioButton is always selected/checked.

    I tried radioButton1.setChecked(false) right after initialization of the radiobutton(inside onCreate), but when the activity starts, I can't manually check/select the first radiobutton. Till I select the 2nd or 3rd radio button, I can now select/check the first radio button.

  • CrazyLearner
    CrazyLearner over 9 years
    As far I know, there is no class named "RadioButtonGroup". Instead of this, the appropriate class name is "RadioGroup". Beyond this tiny fact, the above codes are precisely workable!.
  • Shubham AgaRwal
    Shubham AgaRwal over 7 years
    what if we want to do that in OnCheckedChangeListener ?? for future question why do you do that i have different type views in radio grp in addition to radio btn !
  • Arbaz.in
    Arbaz.in about 4 years
    after setting this radio button background drawable selector not working
  • Ayxan Haqverdili
    Ayxan Haqverdili about 4 years
    Is there a way to do that without the wacky unchecking animation?