【发布时间】:2018-01-12 19:19:33
【问题描述】:
如果我最初预选多个 RadioButton,Android API Level 24(模拟器)似乎允许多选。我只是想知道这是否是一个错误?
这是布局文件:
<?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>
应用启动如下:
如果我点击 Jazz,它会变成这样:
【问题讨论】:
-
可能不是一个错误,我会解释,所以你在 xml 中检查了两个但没有设置单选,因为如果你希望用户只选择一个使单选组成为单选,用户可以选择他想要的选择。
-
尝试将
android:id值分配给RadioButton小部件。见this issue。 -
@CommonsWare,谢谢,分配 id 成功了,最后一个设置为检查在 UI 中检查。顺便说一句,我正在研究你的书:)
标签: android radio-group