Reputation: 2809
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.
Upvotes: 47
Views: 32609
Reputation: 1042
use this
RadioButton spec1=findViewById(yourRadioGroup.getCheckedRadioButtonId());
if (spec1.isChecked())
{
spec1.setChecked(false);
}
Upvotes: 3
Reputation: 40426
RadioGroup radioGroup = (RadioGroup)findViewById(R.id.radiogroup);
radioGroup.clearCheck();
Upvotes: 119
Reputation: 132992
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();
}
Upvotes: 4