2
如果我预先选择多个RadioButton,Android API级别24(模拟器)似乎允许多选。我只是想知道这是否是一个错误?Android RadiGroup允许多选
这里是布局文件:
<?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>
启动应用这样的:
如果我点击爵士,就变成这样:
可能不是一个错误,我会解释所以你检查了两个XML但没有设置单一的选择,因为用户可以选择他想要的,如果你想让用户只选择一个使广播组单选。 –
尝试将'android:id'值赋给'RadioButton'小部件。请参阅[此问题](https://issuetracker.google.com/issues/36910867)。 – CommonsWare
@CommonsWare,谢谢,分配id做了窍门,在UI中检查最后一个设置为检查。顺便说一句,我正在研究你的书:) –