文章标题
来源:互联网 发布:李荣浩后羿知乎 编辑:程序博客网 时间:2024/04/30 21:21
RecyclerView 和CheckBox错乱的解决方案
主要思路是利用setTag()方法将所有和用户交互的CheckBox状态储存在hashmap中,然后在onBindView()方法中利用tag来过去相应的状态并设置,这样就可以避免因为Recyclerview的复用而造成的checkbox错乱的问题.代码如下
@Overridepublic void onBindViewHolder(final MyViewHolder holder, final int position) { holder.checkBox.setTag(position); if (checkmap.get(position)==null){ holder.checkBox.setChecked(false); }else { holder.checkBox.setChecked(checkmap.get((Integer)holder.checkBox.getTag())); } Log.e("tag",position+"######### "); holder.checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { Log.e("tag",position+"****** "+b); checkmap.put((Integer) holder.checkBox.getTag(),b); } }); }
0 0
- 文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题 文章标题 文章标题 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 微信小程序实现简单定位功能
- Devexpress ChartControl 显示平均线(垂直x轴和垂直y轴直线)
- 控件连续点击两次及多次
- spring cron表达式
- mysql数据库数据类型图解
- 文章标题
- 数据库常用操作语句
- JDK中plugin.jar包目录结构
- POJ No.3617-Best Cow Line(字典序最小问题)
- Java的锁机制
- python 环境搭建(二) pip源的修改
- 【新手】关于进制转换
- codeforces 740A Alyona and copybooks
- Codeforces Round #382 (Div. 2) 735A - Ostap and Grasshopper