Naveen Bathina
Naveen Bathina

Reputation: 414

How to allign 2x2 radio buttons into a group in android

I'm new to android please let me know what I have made wrong, I have added a radio group and next added Gridlayout to align radio buttons in 2x2 form of matrix, it aligned good, but problem is that it is not deselecting previously selected options when I select any radio button. How can I achieve this ?

All radio buttons are getting selected. None of them are deselecting upon changing selection of radio button. Please suggest me any approach.

Thanks

Please check attached image for reference

<RadioGroup
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <GridLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="New RadioButton"
                android:id="@+id/radOption1"
                android:layout_row="0"
                android:layout_column="0"
                android:padding="5dp" />

            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="New RadioButton"
                android:id="@+id/radOption2"
                android:layout_row="0"
                android:layout_column="1"
                android:padding="5dp" />

            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="New RadioButton"
                android:id="@+id/radOption3"
                android:layout_row="1"
                android:layout_column="0"
                android:padding="5dp" />

            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="New RadioButton"
                android:id="@+id/radOption4"
                android:layout_row="1"
                android:layout_column="1"
                android:padding="5dp" />

    </GridLayout>
</RadioGroup>

Upvotes: 0

Views: 2999

Answers (1)

Bartek Lipinski
Bartek Lipinski

Reputation: 31438

RadioGroup is basically a LinearLayout within which you can align your RadioButtons. It's not like a generic layout that can store anything (GridLayout in your example) and it will handle any RadioButtons that you will put down in the hierarchy.

TLDR: RadioGroup lets you align your RadioButtons horizontally or vertically - it's a LinearLayout.

The thing you need to do is described in this question.

Upvotes: 1

Related Questions