Android - RadioButton 未取消选中初始选中状态 [英] Android - RadioButton isn't uncheck with initial checked state
本文介绍了Android - RadioButton 未取消选中初始选中状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 RadioGroup 中有一个 RadioButton,
I have a RadioButton within a RadioGroup,
当我设置按钮的初始状态时出现问题
the problem arises when i set the initial state of the button
android:checked = "true"
android:checked = "true"
因为如果我按下单选按钮F",单选按钮M"不会取消选中...
because if I press the RadioButton "F" the RadioButton "M" doesn't uncheck...
我该怎么办?怎么了?
代码如下:
<RadioGroup
android:id="@+id/registrazione_utente_sesso"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="M"
android:textColor="#ff7415"
android:textSize="18sp" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="13.33dp"
android:text="F"
android:textColor="#ff7415"
android:textSize="18sp" />
</RadioGroup>
屏幕:
初始状态(正确):
当我按下 RadioButton "F" 时的最终状态(错误):
final state when i press RadioButton "F" (wrong):
谢谢
推荐答案
使用 android:id 为单选按钮分配唯一的 id,然后设置 RadioGroup 的 android:checkedButton 属性,如下所示:
Assign an unique id to the radio buttons with android:id, then set the android:checkedButton attribute of the RadioGroup, like this:
<RadioGroup
android:id="@+id/registrazione_utente_sesso"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:checkedButton="@+id/radiobutton_m" >
<RadioButton
android:id="@+id/radiobutton_m"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="M"
android:textColor="#ff7415"
android:textSize="18sp" />
<RadioButton
android:id="@+id/radiobutton_f"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="13.33dp"
android:text="F"
android:textColor="#ff7415"
android:textSize="18sp" />
</RadioGroup>
这篇关于Android - RadioButton 未取消选中初始选中状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文