Reputation: 940
I have a RadioGroup
with 6 radio buttons inside it.
Is there a way to uncheck the radio buttons if the user click on an already checked radio button?
I mean is there any way to clear check the whole radio group or do not store the value if user clicks on an already checked radio button
?
i know there exist ClearCheck() and setChecked(false), but i don't know how and where to use them because SetOncheckChanged listener only runs when the check state changes. It does not run when you click on an already checked radio button. I think I should use SetOnClickListener for radiogroup but i don't know how to find which radiobutton is checked?
Upvotes: 1
Views: 2621
Reputation: 5707
Use ::
// if we already have a checked radiobutton and want to remember it
if(mCurrentlyCheckedRB == null)
mCurrentlyCheckedRB = (RadioButton) v;
mCurrentlyCheckedRB.setChecked(true);
}
//clicked the current or desire one to check it that allready stored
if(mCurrentlyCheckedRB == v)
return;
// else, uncheck the currently checked RadioButton, check the new radio button
mCurrentlyCheckedRB.setChecked(false);
((RadioButton)v).setChecked(true);
mCurrentlyCheckedRB = (RadioButton)v;
Upvotes: 2