Reputation: 2186
I am developing a quiz application which consists of a question and three options and I am using radio buttons for these options.My query is,I click on one of the options and whenever i want to click another option, the previous option remains in the checked state and it does the same whenever I click on the third option too. I need a solution where in it behaves as a natural radio button,only one option is checked at any point of time.
Upvotes: 4
Views: 5162
Reputation: 33996
You can group RadioButtons using the RadioGroup. Here is the example how you can group the RadioButtons using RadioGroup
<RadioGroup android:id="@+id/radioGroup1" android:layout_width="wrap_content" android:layout_height="wrap_content">
<RadioButton android:text="RadioButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/radio0" android:checked="true"></RadioButton>
<RadioButton android:text="RadioButton" android:layout_width="wrap_content" android:id="@+id/radioButton1" android:layout_height="wrap_content"></RadioButton>
</RadioGroup>
For more information you can refer this document
Upvotes: 4
Reputation: 113
set your radio buttons to onclicklistener and manually change states of every radio button. For example if you clicked 1st radio button set first to selected and rest to not selected
Upvotes: -1
Reputation: 1830
You need to put the radio buttons into a radio group, which will then provide the 'only one selected at any time' functionality that you want. See here for more info, such as:
It's important that the
RadioButtons
are grouped together by theRadioGroup
element so that no more than one can be selected at a time. This logic is automatically handled by the Android system. When oneRadioButton
within a group is selected, all others are automatically deselected.
Upvotes: 1