Android RadiGroup allows multiple selection

Android API level 24 (emulator) seems to allow multiple options if I preselect multiple RadioButtons initially. I just want to know if this is a bug or not?

Here is the layout file:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RadioGroup
        android:id="@+id/radioGroup"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

       <RadioButton
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:text="@string/metal"
           android:checked="true"/>

        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/classical"
            android:checked="true"/>

        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/jazz"/>

    </RadioGroup>

</LinearLayout>

      

The application starts as follows:

enter image description here

And if I hit Jazz, it goes something like this:

enter image description here

+3


source to share


1 answer


Your layout is missing android:id

values ​​for widgets RadioButton

. This might work as long as you don't start with any of these pre-checked in the layout resource. If you are going to use android:checked

in a layout resource, you need to assign widget ids to widgets RadioButton

. This is a long-standing problem that is unlikely to change, which is why "it's just one of those things" that we have to deal with in Android application development.



+3


source







All Articles