Reputation: 266
I have added 2 RadioButtons under RadioGroup and enabled first one, when i selecting second one its not deselecting first one. can you suggest me what was the wrong in this
Here is my xml:
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:orientation="horizontal">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="NO"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="YES"/>
</RadioGroup>
Upvotes: 3
Views: 5320
Reputation: 2108
Just give IDs to all radio buttons. It'll work.
android:id="@+id/radioButton1/2/3"
Upvotes: 1
Reputation: 4032
Try This:
<RadioGroup
android:id="@+id/radioGrp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:orientation="horizontal">
<RadioButton
android:id="@+id/radio1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="NO"/>
<RadioButton
android:id="@+id/radio2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="YES"/>
</RadioGroup>
Upvotes: 4
Reputation: 569
I think android:checked="true"
makes it selected infinitely.
Try defaulting first button in your code.
radiogroup.check(idOfYourFirstRadio)
You need to set IDs to your Views.
Upvotes: 0