1
votes

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?

1
I thought that the purpose of a radioGroup was to limit checkedness to a single radioButton.Scary Wombat
In these cases, first i get first checked radiobtn to tempRdBtn, then when another one checked, i uncheck the tempRdBtn and putting new checked one to this. Maybe this helps you.alicanbatur
This radio button will become unchecked when user selects any of the other 5 buttons. If you want to give user the option to not make an entry, try giving a 7th button as "None of the above" than trying to uncheck all.Shakti
Yeah that is really a good solution Shakti. thanks.SMahdiS

1 Answers

2
votes

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;