博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
硬编码写RadioGroup的时候要注意RadioButton的id重复问题
阅读量:6913 次
发布时间:2019-06-27

本文共 1289 字,大约阅读时间需要 4 分钟。

hot3.png

硬编码写RadioGroup的时候要注意RadioButton的id重复问题,导致选择的时候出现能够多选的情况发生,如下代码,注意Id的设置,这样避免Radiobutton的id重复。

/**	 * 生成单选按钮	 * 	 * @param strTextView	 * @param stringList	 * @param culName	 *  	 */	private View getRadioGroup(String strTextView, List
stringList, String culName,int j) { String strValues = readFromSharedpreferences(culName); LayoutInflater inflater = getLayoutInflater(); LinearLayout view = (LinearLayout) inflater.inflate(R.layout.form_radiogroup, null); TextView textView = (TextView) view.findViewById(R.id.tv_edittext); textView.setTextColor(Color.BLACK); textView.setTextSize(18); textView.setText(strTextView); RadioGroup radioGroup = (RadioGroup) view.findViewById(R.id.my_radiogroup); radioGroup.setOrientation(LinearLayout.HORIZONTAL); for (int i = 0; i < stringList.size(); i++) { RadioButton radioButton = new RadioButton(getApplicationContext()); radioButton.setText(stringList.get(i).toString()); if (strValues != null && strValues.equals(stringList.get(i).toString())) { hashMap.put(culName, strValues); radioButton.setChecked(true); } radioButton.setId(100*j+i); radioButton.setTextColor(Color.BLACK); radioGroup.addView(radioButton); } view.setTag(radioGroup); return view; }

转载于:https://my.oschina.net/keeponmoving/blog/83333

你可能感兴趣的文章
不偏移的天地图地图服务-SuperMap版
查看>>
Three.js 关于照相机,视角的理解
查看>>
开始学习了
查看>>
centos6.4下安装php的imagick和imagemagick扩展教程
查看>>
mysql
查看>>
封装cookie localStorage sessionStorage
查看>>
struts系列:返回json格式的响应
查看>>
Eular筛法
查看>>
关于串口通信的学习记录
查看>>
为什么zookeeper的节点配置的个数必须是奇数个?
查看>>
matplotlib 进阶之Legend guide
查看>>
WMI中相关的操作说明execquery 或者是instancesof
查看>>
Pig 实现关键词匹配
查看>>
PROJ.4学习——坐标系转换
查看>>
File类&递归
查看>>
显示应用名称
查看>>
2014.5.7—社交网络用户心理分析
查看>>
Tesla-> Fermi (550Ti) -> Kepler(680) -> Maxwell (750Ti) -> Volta(was Pascal)
查看>>
[FATAL_ERROR] Cannot start Maven: No valid Maven installation found. Either
查看>>
存入azure table时忽略某个属性
查看>>