listView嵌套radiobutton
来源:互联网 发布:spss如何输入数据 编辑:程序博客网 时间:2024/05/11 01:29
跟大多数一样,思路就是将状态存储到map中,再回显
定义map存储选中的状态,key为item的position,值为0和1代表这选择的是第一个radiobutton还是第二个,这里是二个radiobutton,其他的类似
private Map<Integer, Integer> mapRadioBtn=new HashMap<Integer, Integer>();
别的不贴了。贴一下getview方法,主要就是getview
public View getView(final int position, View convertView, ViewGroup parent) { if (convertView==null) { convertView=View.inflate(getApplicationContext(), R.layout.item_activity_addbuildingrecode, null); } final RadioButton radioBtn1=ViewHolder.get(convertView, R.id.item_addbuildingrecode_radioBtn1); final RadioButton radioBtn2=ViewHolder.get(convertView, R.id.item_addbuildingrecode_radioBtn2); final RadioGroup mRadioGroup=ViewHolder.get(convertView, R.id.item_addbuildingrecode_radioGroup); // mRadioGroup.setTag(position); mRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { if (radioBtn1.isChecked()||radioBtn2.isChecked()) { if (checkedId==radioBtn1.getId()) {//设定radiobutton1为0,radiobutton2为1 mapRadioBtn.put(position, 0); MLog.e("main", "put"+position); }else if (checkedId==radioBtn2.getId()) { mapRadioBtn.put(position, 1); MLog.e("main", "put"+position); } }else { } } }); if (mapRadioBtn.keySet()!=null&&mapRadioBtn.containsKey(position)) { MLog.e("main","恢复keyset"+mapRadioBtn.keySet().toString() +position); if (mapRadioBtn.get(position)==0) { radioBtn2.setChecked(true);//恢复第一个选中(先选中第二个,实现切换效果,否则重复选择第一个,会出现第一个以选择但是选中图标不出现) MLog.e("main","选中第一个"); radioBtn1.setChecked(true); }else if (mapRadioBtn.get(position)==1) { radioBtn1.setChecked(true); MLog.e("main","选中第二个"); radioBtn2.setChecked(true); } }else { MLog.e("main","不包含keyset"+mapRadioBtn.keySet().toString()+position ); radioBtn1.setChecked(false); radioBtn2.setChecked(false); } if (mapRadioBtn!=null) { MLog.e("main","map的keyset"+mapRadioBtn.keySet().toString() ); } return convertView; }
其中在恢复时发现了个bug,调了很久,本来走了恢复的方法,但是一直不是选中状态,经研究发现,确实已经选中了,只是界面选中效果看不到,即图标没有换为选中图标,不知为何,自己的解决办法有点low,就是先选择一下另一个在选回来,这样效果救出来了(研究时发现如果第一个被选中,在恢复时有setchecked一下它,就会变为为选中状态图标,所以想到切换一下,避免重复选中一个radiobutton,low死了,但是解决了),如果有帮助可以借鉴一下,有好的办法也分享一下哈,谢谢
0 0
- listView嵌套radiobutton
- ListView中嵌套RadioButton按钮
- ListView嵌套radiobutton的互斥解决方案
- Listview里嵌套radiobutton,默认只有一个可以被选中
- ListView & RadioButton
- listview添加radiobutton
- RadioButton listView实现
- listview嵌套
- 嵌套listview
- ListView嵌套
- ListView中嵌套ListView
- listview嵌套listview
- ListView嵌套ListView优化
- ListView中嵌套listView
- ListView中嵌套ListView
- 关于listview嵌套listview
- ListView嵌套ListView
- ListView中嵌套ListView
- js闭包使用及建议
- WebStorm快捷键操作
- >LINK : fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏
- Codeforces Problem 711A Bus to Udayland(brute force+implementation)
- 软件工程师的好习惯
- listView嵌套radiobutton
- MySQL存储过程,定时器
- 程序设计进阶 编程题#6:流感传染
- cocos 2dx 3.12 学习笔记(二) Sprite
- Interpreter模式
- [阶段二]Android UI进度组件
- 限制textarea字数并实时显示输入字…
- nginx 搭建LDAP认证
- android system alter window实现系统提示框