46

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.

Pratik Butani
  • 60,504
  • 58
  • 273
  • 437
Jayson Tamayo
  • 2,741
  • 3
  • 49
  • 76

3 Answers3

117
RadioGroup radioGroup = (RadioGroup)findViewById(R.id.radiogroup);
radioGroup.clearCheck();
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
Samir Mangroliya
  • 39,918
  • 16
  • 117
  • 134
  • 1
    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!. – CrazyLearner Nov 08 '14 at 09:13
  • 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 ! – Shubham AgaRwal Jan 12 '17 at 11:49
  • 1
    Is there a way to do that without the wacky unchecking animation? – Aykhan Hagverdili Jun 24 '20 at 03:07
4

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();  
    }  
ρяσѕρєя K
  • 132,198
  • 53
  • 198
  • 213
3

use this

RadioButton spec1=findViewById(yourRadioGroup.getCheckedRadioButtonId());
        if (spec1.isChecked())
        {
            spec1.setChecked(false);
        }
Prabh deep
  • 1,024
  • 11
  • 15