AppCompatRadioButton的RadioGroup在Jelly Bean上不起作用?

3
我有一个使用支持库中的AppCompatRadioButtons创建的相当简单的单选按钮组。然而,在Lollipop之前的版本上,该组似乎无法正常工作。我能够选择每个选项,但找不到任何原因。
我正在使用运行4.1的模拟器进行测试。如下所示,我可以选择多个选项。

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>

在Lollipop和Marshmallow上进行测试会得到所需的结果。

我已经在安装有Jellybean版本的HTC设备上测试了相同的布局。它运行良好...每次只能选择一个AppCompatRadioButton。 - Anil Chandra Varma Dandu
1个回答

1
为每个AppCompatRadioButton定义唯一的ID。例如:
<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>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接