动态添加RadioGroup组件的RadioButton出现多选状况解决
2016-07-14 14:01
369 查看
动态添加RadioGroup组件的RadioButton出现多选状况解决
(1)使用radiogroup组件时,每个radiobutton必须有一个id,否则会出现多选,不管是xml文件还是动态添加;
(2)每一个radiobutton最好不要嵌套任何父布局,父布局直接为radiogroup即可;
(3)确保radiobutton的id不会重复,如果是在xml中,则可以直接报错,而在动态添加时,如果radiobutton的id是一样的,不会报错,但会出现多选的状况。
(1)使用radiogroup组件时,每个radiobutton必须有一个id,否则会出现多选,不管是xml文件还是动态添加;
(2)每一个radiobutton最好不要嵌套任何父布局,父布局直接为radiogroup即可;
(3)确保radiobutton的id不会重复,如果是在xml中,则可以直接报错,而在动态添加时,如果radiobutton的id是一样的,不会报错,但会出现多选的状况。
for (int i = 0; i < selectableGoodsPropertyList.size(); i++) { TextView tv_name = new TextView(ProductDetails.this); RadioGroup group = new RadioGroup(ProductDetails.this); group.setOrientation(LinearLayout.HORIZONTAL); group.setId(i); groupName = selectableGoodsPropertyList.get(i).propertyName; tv_name.setText(groupName); propertyValueList = selectableGoodsPropertyList.get(i).goodsPropertyValueList; for (int j = 0; j < propertyValueList.size(); j++) { RadioButton btn = new RadioButton(ProductDetails.this); btn.setText(propertyValueList.get(j).propertyValue); btn.setId(i*(j+20)+30+j); group.addView(btn); } ll_type_properties.addView(tv_name); ll_type_properties.addView(group); groups.add(group); group.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { int groupId = group.getId(); HashMap map = new HashMap(); RadioButton checkedbutton = (RadioButton) group.findViewById(checkedId); map.put(groupId+"", checkedbutton.getText().toString()); properties.add(map); cartPropertiesList.add(checkedbutton.getText().toString());
相关文章推荐
- OpenStack Icehouse Installation: Two-node architecture with legacy networking (nova-network)
- merge conflicts with git
- SVN服务器与客户端下载地址_搭建使用
- 深入理解javascript原型和闭包(3)——prototype原型
- 深入理解javascript原型和闭包(2)——函数和对象的关系
- 命名空间、静态函数、实例函数
- 工厂模式-创建型
- Mac eclipse 安装svn插件
- 前端开发主要的工具学习网站
- SVN clean失败解决方法
- javaweb学习总结(四)——Http协议
- Android Material Design之Toolbar与Palette实践
- JavaEE 获取路径全攻略
- 选择排序
- JQ实现函数连续不断的重复执行
- shell学习-10-函数
- 【解决】通用串行总线控制器全是感叹号
- 深入理解javascript原型和闭包(1)——一切都是对象
- 对数据交换平台,教育行业大数据平台的思考
- Android布局xml布局文件