RadioButton设置默认选中后无法取消,可选中多个的问题
今天在做项目的时候出现一个低级错误,在多个RadioButton中,给其中RadioButton默认选中(android:checked="true"),运行后发现这个选中的RadioButton无法取消了,出现在一个RadioGroup中可以选择多个RadioButton的问题。这问题也许有点low,不过还是记录下给自己一个提醒吧。
这应该是基础不好的原因
问题:
在一个RadioGroup中可以选中两个RadioButton,且默认选中的那个一直为选中状态
代码:(简化后的代码,原来有很多属性)
<RadioGroup android:layout_height="wrap_content"android:layout_width="wrap_content"><RadioButton android:layout_height="wrap_content"android:layout_width="wrap_content"android:checked="true"android:text="1"/><RadioButton android:layout_height="wrap_content"android:layout_width="wrap_content"android:text="2"/><RadioButton android:layout_height="wrap_content"android:layout_width="wrap_content"android:text="3"/></RadioGroup>
然后我就纳闷了好久,说好的单选呢???
接着就是百度,Google...找了好久也没找到答案(不知道是不是提问的方式不对),总之没找到结果
只好一个个属性删掉看看有没有问题(原来RadioButton有很多属性的),功夫不负有心人啊!!!最后还是找到原因了
上新的代码:
<RadioGroupandroid:layout_width="wrap_content"android:layout_height="wrap_content" ><RadioButtonandroid:id="@+id/r1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:checked="true"android:text="1" /><RadioButtonandroid:id="@+id/r2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="2" /><RadioButtonandroid:id="@+id/r3"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="3" /></RadioGroup>
好像没什么区别啊,再仔细看看...比原先多了id这个属性
原来RadioButton是要设置id这个属性的,不然会导致RadioButton不互斥,后果很严重的啊
以上有错误之处欢迎指出,谢谢!!!
RadioButton设置默认选中后无法取消,可选中多个的问题相关推荐
- html中select标签默认选择,HTML中的select标签如何设置默认选中的选项
方法有两种. 第一种通过的属性来设置选中项,此方法可以在动态语言如php在后台根据需要控制输出结果. 1 2 3 4 5 1 option > 2 option > 3 option &g ...
- vue中单选框设置默认选中值
vue中单选框的默认选中不同于传统方式设置checked,是通过在data中设置vulue来实现的 html部分是通过v-for取的后台的数据 <li v-for="(value,i) ...
- Vue select的使用以及select设置默认选中,element select联动不能选择问题
Vue中select下拉框的默认选中项的三种情况_vue option默认选择_July++的博客-CSDN博客 vue中select的使用以及select设置默认选中_燕山八音的博客-CSDN博客 ...
- html设置默认选中状态,html中select标签用法解析及如何设置select的默认选中状态...
当提交表单时,浏览器会提交选定的项目,或者收集用逗号分隔的多个选项,将其合成一个单独的参数列表,并且在将 表单数据提交给服务器时包括 name 属性. 标签可选的属性 属性 值 ...
- vue 复选框默认选中_vue 实现单选框设置默认选中值
vue 实现单选框设置默认选中值 vue中单选框的默认选中不同于传统方式设置checked,是通过在data中设置vulue来实现的 html部分是通过v-for取的后台的数据 生成后的代码就是 js ...
- 【Element UI】日期选择器el-date-picker 默认选中当前日期==> 不可选当日之前的日期
一个人能否合理表达自己的攻击性是健康与否的重要标准. 参考Element UI Element - The world's most popular Vue UI framework 目录 1.默认 ...
- html中radio单选按钮控件标签用法解析及如何设置默认选中
Radio 对象代表 HTML 表单中的单选按钮.在 HTML 表单中 <input type="radio"> 每出现一次,一个 Radio 对象就会被创建.单选按钮 ...
- php导航默认选中,html中关于select标签如何设置默认选中的选项详解
方法有两种. 第一种通过的属性来设置选中项,此方法可以在动态语言如php在后台根据需要控制输出结果.< select id = "sel" > < option ...
- layuitable设置默认选中
layuiTable设置默认选中 此语句作用是修改table列选中的依据,根据Checked字段的状态来判断改行是否选中,这里Checked为bool类型 table = $.extend(table ...
最新文章
- 激活函数之logistic sigmoid函数介绍及C++实现
- PostgreSQL专题
- Python 基础:分分钟入门
- Java 的toString() 和 equals()函数简单介绍
- C++类对象在内存中的布局
- Spring AOP技术(基于AspectJ)的XML开发
- SIP应答代码【ZT】
- csp ccf 202206-2 寻宝!大冒险!(70分超时的进)
- php 七牛云获得上传token,客户端生成七牛上传token
- android平台获取手机IMSI,IMEI ,序列号,和 手机号的方法
- php 半角全角转换,php 把全角字符转换成半角
- JS的报错处理(throw、try、catch)
- C#腾讯地图Web端定位地址搜索及手机导航
- 微信内置浏览器 非全屏播放视频解析
- 网页配色不用愁!6条网页设计配色原则
- 使用redis实现缓存_用下一个js实现一个简单的redis缓存
- linux静默安装oracle11g数据库教程
- 4.1nbsp;需求定律分析
- Windows10安装IDEA 2020.1.2及你懂得
- NVIDA CUDA-DirverAPI入门