RadioButton是一种单选按钮
故选择是只有一个的,但是在开发中却会出现RadioButton可以多选的现象,究其原因,发现只有在RadioButton中添加了id属性才可以实现单选的作用,如果没有添加id属性,就会在模拟器中出现可以多选的现象
正确的写法:
<RadioGroup android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="15dp" android:orientation="horizontal" > <RadioButton android:id="@+id/rbMale" android:checked="true" android:text="男" /> <RadioButton android:id="@+id/rbFmale" android:text="女" /> </RadioGroup>
错误的写法:
<RadioGroup android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="15dp" android:orientation="horizontal" > <RadioButton android:checked="true" android:text="男" /> <RadioButton android:text="女" /> </RadioGroup>