【问题标题】:RadioGroup for AppCompatRadioButtons not working on Jelly Bean?AppCompatRadioButton 的 RadioGroup 不适用于 Jelly Bean?
【发布时间】:2016-03-28 10:59:07
【问题描述】:

我使用支持库中的 AppCompatRadioButtons 创建了一个相当简单的单选按钮组。然而,该小组似乎并没有在棒棒糖之前的版本上工作。我可以选择每个选项,但找不到任何关于它为什么这样做的迹象。

我正在使用运行 4.1 的模拟器进行测试。正如您在下面看到的,我可以选择多个选项。

<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

标签: android radio-button radio-group


【解决方案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>

【讨论】:

    猜你喜欢
    • 2014-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多