srinu
srinu

Reputation: 266

Why RadioGroup Selecting multiple RadioButtons

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

Answers (4)

Pranav Mahajan
Pranav Mahajan

Reputation: 2108

Just give IDs to all radio buttons. It'll work.

android:id="@+id/radioButton1/2/3"

Upvotes: 1

Omar Vodiak
Omar Vodiak

Reputation: 116

Remove android:checked="true" and should be good

Upvotes: 0

Amy
Amy

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

Suhyeon Lee
Suhyeon Lee

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

Related Questions