Reputation: 450
How can I make a grouping of RadioButton
, of which at most one can be checked, but which allows all buttons to be unchecked? (I maintain that this has always been one of two common behaviours for groups of radio buttons.)
I haven't managed to get this to work with RadioGroup
. It allows all the buttons to be unchecked on creation, but once one button is checked, there seems no way to get back to the original all-unchecked state. (Sure, in a parent's onRadioButtonClicked()
, all the buttons can be unchecked -- but unfortunately by the time this is called, an unchecked button will already have been checked. So I think it would be necessary to keep a separate accounting of which buttons were previously checked, in order to use that.)
Two options have occurred to me.
One is to make my own "ReasonableRadioGroup", that allows both common behaviors. Seems a little extreme.
Another is to arrange for a long-click event on a checked button to uncheck the button -- but I don't think that would be obvious to a user.
But surely I'm just missing something!
Upvotes: 1
Views: 106
Reputation: 1076
Did you try :
RadioGroup radioGroup = (RadioGroup)findViewById(R.id.radiogroup);
radioGroup.clearCheck();
Upvotes: 0
Reputation: 1006614
How can I make a grouping of RadioButton, of which at most one can be checked, but which allows all buttons to be unchecked?
Sorry, there is no support for that in the RadioButton
/RadioGroup
classes in the Android SDK. It is possible that one of these libraries offers that, though it does not look promising.
But surely I'm just missing something!
No, sorry.
Upvotes: 1