Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RadioGroup for AppCompatRadioButtons not working on Jelly Bean?

I have a fairly simple radio button group created with the AppCompatRadioButtons from the support library. However, the group does not seem to work on pre Lollipop versions. I am able to select every option and cannot find any indication on why it is doing this.

I am testing with an emulator running 4.1. As you can see below I can select multiple options.

enter image description here

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

    <android.support.v7.widget.AppCompatRadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="W"/>

    <android.support.v7.widget.AppCompatRadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Q"/>

    <android.support.v7.widget.AppCompatRadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="B-Hum"/>

    <android.support.v7.widget.AppCompatRadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="B-Sci"/>

    <android.support.v7.widget.AppCompatRadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="B-Soc"/>
</RadioGroup>

Testing on Lollipop and Marshmallow gets required results.

like image 738
SikhWarrior Avatar asked Dec 15 '25 19:12

SikhWarrior


1 Answers

Define a unique ID for each AppCompatRadioButton. For example:

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

    <android.support.v7.widget.AppCompatRadioButton
        android:id="@+id/radio_w"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="W"/>

    <android.support.v7.widget.AppCompatRadioButton
        android:id="@+id/radio_q"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Q"/>

    <android.support.v7.widget.AppCompatRadioButton
        android:id="@+id/radio_bhum"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="B-Hum"/>

    <android.support.v7.widget.AppCompatRadioButton
        android:id="@+id/radio_bsci"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="B-Sci"/>

    <android.support.v7.widget.AppCompatRadioButton
        android:id="@+id/radio_bsoc"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="B-Soc"/>

</RadioGroup>
like image 133
jasonchen2 Avatar answered Dec 17 '25 17:12

jasonchen2



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!