zoukankan      html  css  js  c++  java
  • listview中item 有checkbox多选防止滑动 listview页面 出现checkbox错位问题

    checkbox点击切换背景

      <CheckBox
            android:id="@+id/checkbox"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:button="@null"
            android:focusable="false"
            android:background="@drawable/playimage" />

    drawable文件夹下切换背景

    /Day07_music/res/drawable/playimage.xml

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android" >
        <item android:state_selected="true"  android:drawable="@drawable/pause"></item>
       <item android:state_checked="true" android:drawable="@drawable/pause"></item>
        <item android:state_pressed="true" android:drawable="@drawable/pause"></item>
        <item android:drawable="@drawable/forward"></item>
    
    </selector>

    适配器下面找到checkbox

    在list集合里设置 一个 boolean 值 记录选中状态

    在适配器下对checkbox进行监听

    解释:通过setOnCheckedChangeListener监听记录状态 然后通过setOnClickListener判断当前状态进行操作 避免因为滑动listview界面导致checkbox值改变,也就是说checkbox值是用户点击而改变避免滑动listview界面自动改变

     //记录当前checkbox改变状态
            viewHolder.checkBox
                    .setOnCheckedChangeListener(new OnCheckedChangeListener() {
    
                        public void onCheckedChanged(CompoundButton buttonView,
                                boolean isChecked) {
                            // TODO Auto-generated method stub
                            //checkbox改变
                            list.get(position).setBo(isChecked);
                        }
                    });
    //判断是点击改变的 viewHolder.checkBox.setOnClickListener(
    new OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub for (int i = 0; i < list.size(); i++) { boolean bo = list.get(i).getBo(); //判断选中 if (bo) { //选中要执行的 } } //刷新适配器 notifyDataSetChanged(); } }); //chebox选中显示 viewHolder.checkBox.setChecked(list.get(position).getBo());
  • 相关阅读:
    这几天的读书心得
    随机接入过程的步骤
    从tlb,ocx,dll类型库中提取com组件的CLSID
    unicode字符集下CStdioFile无法写入中文的解决方案
    多线程CString参数传递问题
    yii2.0 报错Cookievalidationkey Must Be Configured With A Secret Key
    windows下的phpunit安装
    xdebug 一直报错 upstream timed out (110: Connection timed out) while reading response header from upstream
    session与cookie
    【转】LVS负载均衡之session解决方案 持久连接
  • 原文地址:https://www.cnblogs.com/1426837364qqcom/p/5397972.html
Copyright © 2011-2022 走看看