标签:android radio-button radio-group
我在RadioGroup中有一个RadioButton,
当我设置按钮的初始状态时出现问题
android:checked = “true”
因为如果我按下RadioButton“F”,则RadioButton“M”不会取消选中…
我能怎么做?怎么了?
这是代码:
<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”的最终状态(错误):
谢谢
解决方法:
使用android:id为单选按钮分配一个唯一的id,然后设置RadioGroup的android:checkedButton属性,如下所示:
<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,radio-button,radio-group 来源: https://codeday.me/bug/20190901/1787281.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。