zoukankan      html  css  js  c++  java
  • ListView中CheckBox错乱解决

    思路:
    ListView在复用的时候会出现很多问题,CheckBox状态会出现错乱,解决思路:
    1.使用Map集合的键值对的形式来存放position位置上CheckBox的状态
    2.监听CheckBox的状态改变Listener,如果选中就往Map中添加一个position,true  如果取消,则将map中对应的键值对移除。

    直接代码:

     
    private Map<Integer, Boolean> isCheckMap =  new HashMap<Integer, Boolean>();  
     
     
    holder.check,setTag(position);
    if (isCheckMap!= null  && isCheckMap.containsKey(position)) {
                holder.checkBox.setChecked(isCheckMap.get(position));
            }else {
                holder.checkBox.setChecked(false);
            } 
     
     
     holder.checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
                    @Override
                    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                            if(isChecked)
                            {
                                //将选中的放入hashmap
                                isCheckMap.put(position, isChecked);
                            }
                            else
                            {
                                //取消选中的则剔除
                                isCheckMap.remove(position);
                            }
                    }
                });





  • 相关阅读:
    Java 介绍比较全面的一遍文章
    JSP页面中path和basepath的含义
    myeclipse2014 破解步骤
    word文档去掉复制过来的背景颜色
    String,创建对象问题
    使用Spring框架的好处(转帖)
    myeclipse中将整块的代码所选中的代码左右移动的快捷键
    点击关闭窗口时,弹出提醒的一个事件
    switch能使用的数据类型有6种
    观察者模式(设计模式_15)
  • 原文地址:https://www.cnblogs.com/flyme2012/p/3944833.html
Copyright © 2011-2022 走看看