自定义ExpandableListView带CheckBox中child全选功能


-
ExpandableListView中group和child都带CheckBox,实现child的全选功能,包含部分选中功能,同时实现类似邮件群发的用户选择功能,选中的用户在EditText中显示,点击后移除.
-
2018-06-20
-
2017-04-10
-
2017-03-08
-
2017-01-15
-
2016-07-21
-
2016-05-12
-
2016-03-10
-
2015-11-29
-
2015-09-27
-
2015-09-16
550KB
Android的ExpandableListView+CheckBox全选
2013-11-22ExpandableListView的group和child里面都含有CheckBox框,二者联动。
1014KB
ExpandableListView单选以及多选实现
2015-09-18自己做了小练习,实现了单选以及多选,有需要的同学可以下载!
1.17MB
Android 两级都带CheckBox的 ExpandableListView
2014-06-25Android中两级都实现带CheckBox的 ExpandableListView,实现两级联动选择
android ExpandableListView+CheckBox实现组选列表_course
2015-12-30需要用ExpandableListView+CheckBox实现一个组选列表,ExpandableListView组列表为部门,子列表为成员。需要选中部门的CheckBox时,选中所有组内成员CheckBox,取消时全部取消。选择单个组内成员时,未全部选中该部门成员,则部门CheckBox不勾选,如选中了所有成员,则自动勾选部门CheckBox。希望以前做过的朋友可以给个详细的例子 下面附上我的代码 ``` import android.content.Context; import android.view.View; import android.view.ViewGroup; import android.widget.BaseExpandableListAdapter; import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; import java.util.ArrayList; import java.util.List; import java.util.Map; public class ReportListAdapter extends BaseExpandableListAdapter { private Context context; private List<DepartmentEntity> parentList; private Map<String, List<EmployeeEntity>> map; private List<Boolean> parentStatusList = new ArrayList<Boolean>(); private List<Boolean> childStatusList = new ArrayList<Boolean>(); public ReportListAdapter(Context context, List<DepartmentEntity> parentList, Map<String, List<EmployeeEntity>> map) { this.context = context; this.parentList = parentList; this.map = map; } // 得到子item需要关联的数据 @Override public Object getChild(int groupPosition, int childPosition) { String key = parentList.get(groupPosition).getId(); return (map.get(key).get(childPosition)); } // 得到子item的ID @Override public long getChildId(int groupPosition, int childPosition) { return childPosition; } // 设置子item的组件 @Override public View getChildView(final int groupPosition, final int childPosition, final boolean isLastChild, View convertView, final ViewGroup parent) { if (convertView == null) { convertView = View.inflate(context, R.layout.report_list_child_item, null); } String key = this.parentList.get(groupPosition).getId(); final EmployeeEntity employee = map.get(key).get(childPosition); String name = employee.getName(); TextView employeeName = BaseViewHolder.get(convertView, R.id.employee_name); employeeName.setText(name); CheckBox childCB = BaseViewHolder.get(convertView, R.id.employee_checkbox); // if (employee.isChecked()) { // cb.setChecked(true); // } else { // cb.setChecked(false); // } childCB.setChecked(employee.isChecked()); // notifyDataSetChanged(); childCB.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { CheckBox nowCB = (CheckBox) view; if (nowCB.isChecked()) { employee.setIsChecked(true); // // //获得子item数量 int childSize = getChildrenCount(groupPosition); //其他子item状态 List<Boolean> otherChildStatus = new ArrayList<Boolean>(); otherChildStatus.clear(); for (int i = 0; i < childSize; i++) { if (i != childPosition) { boolean isLastChild1; if (i == childSize - 1) { isLastChild1 = true; } else { isLastChild1 = false; } //获得子item View view1 = getChildView(groupPosition, i, isLastChild1, null, null); CheckBox childCB = (CheckBox) view1.findViewById(R.id.employee_checkbox); boolean cbStatus; if (childCB.isChecked()) { cbStatus = true; } else { cbStatus = false; } otherChildStatus.add(cbStatus); } } //获得父item View parentView1 = getGroupView(groupPosition, true, null, null); //获取父item的cb CheckBox parentCB = (CheckBox) parentView1.findViewById(R.id.department_checkbox); //设置父Item选项框状态 for (int i = 0; i < otherChildStatus.size(); i++) { if (!otherChildStatus.get(i)) { parentList.get(groupPosition).setIsChecked(false); parentCB.setChecked(false); System.out.println("设置父cb不选"); break; } else { parentList.get(groupPosition).setIsChecked(true); parentCB.setChecked(true); notifyDataSetChanged(); System.out.println("设置父cb全选中"); } } notifyDataSetChanged(); } else { //获得父item View parentView = getGroupView(groupPosition, true, null, null); employee.setIsChecked(false); CheckBox parentCB = (CheckBox) parentView.findViewById(R.id.department_checkbox); parentList.get(groupPosition).setIsChecked(false); parentCB.setChecked(false); System.out.println("设置父cb不选"); notifyDataSetChanged(); } } }); // cb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { // @Override // public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) { // //获得父item // View parentView = getGroupView(groupPosition, true, null, null); // if (isChecked) { // employee.setIsChecked(true); // // //获得子item数量 // int childSize = getChildrenCount(groupPosition); // //其他子item状态 // List<Boolean> otherChildStatus = new ArrayList<Boolean>(); // for (int i = 0; i < childSize; i++) { // if (i != childPosition) { // boolean isLastChild1; // if (i == childSize - 1) { // isLastChild1 = true; // } else { // isLastChild1 = false; // } // //获得子item // View view = getChildView(groupPosition, i, isLastChild1, null, null); // CheckBox childCB = (CheckBox) view.findViewById(R.id.employee_checkbox); // boolean cbStatus; // if (childCB.isChecked()) { // cbStatus = true; // } else { // cbStatus = false; // } // otherChildStatus.add(cbStatus); // } // } // //设置父Item选项框状态 // for (int i = 0; i < otherChildStatus.size(); i++) { // CheckBox parentCB = (CheckBox) parentView.findViewById(R.id.department_checkbox); // if (otherChildStatus.get(i) == false) { // parentCB.setChecked(false); // parentList.get(groupPosition).setIsChecked(false); // break; // } else { // parentCB.setChecked(true); // parentList.get(groupPosition).setIsChecked(true); // } // } // notifyDataSetChanged(); // } else { // employee.setIsChecked(false); // CheckBox parentCB = (CheckBox) parentView.findViewById(R.id.department_checkbox); // parentCB.setChecked(false); // parentList.get(groupPosition).setIsChecked(false); // notifyDataSetChanged(); // } // // } // }); return convertView; } // 获取当前父item下的子item的个数 @Override public int getChildrenCount(int groupPosition) { String key = parentList.get(groupPosition).getId(); int size = map.get(key).size(); return size; } // 获取当前父item的数据 @Override public Object getGroup(int groupPosition) { return parentList.get(groupPosition); } @Override public int getGroupCount() { return parentList.size(); } @Override public long getGroupId(int groupPosition) { return groupPosition; } // 设置父item组件 @Override public View getGroupView(final int groupPosition, final boolean isExpanded, View convertView, ViewGroup parent) { if (convertView == null) { convertView = View.inflate(context, R.layout.report_list_parent_item, null); } ImageView mgroupimage = BaseViewHolder.get(convertView, R.id.arrow); mgroupimage.setImageResource(R.mipmap.la); if (!isExpanded) { mgroupimage.setImageResource(R.mipmap.shou); } TextView departmentName = BaseViewHolder.get(convertView, R.id.department_name); departmentName.setText(parentList.get(groupPosition).getName()); final CheckBox cb = BaseViewHolder.get(convertView, R.id.department_checkbox); cb.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { System.out.println("点击了父" + groupPosition); CheckBox nowCB = (CheckBox) view; if (nowCB.isChecked()) { //获取子item的数量 int childSize = getChildrenCount(groupPosition); //子item全选中 for (int i = 0; i < childSize; i++) { //获取子item EmployeeEntity child = (EmployeeEntity) getChild(groupPosition, i); child.setIsChecked(true); boolean isLastChild; if (i == childSize - 1) { isLastChild = true; } else { isLastChild = false; } //获得子item View view1 = getChildView(groupPosition, i, isLastChild, null, null); CheckBox childCB = (CheckBox) view1.findViewById(R.id.employee_checkbox); childCB.setChecked(true); System.out.println("子" + groupPosition + "-" + i + " 已经选中"); } //设置父item被完全选中 parentList.get(groupPosition).setIsChecked(true); cb.setChecked(true); System.out.println("父" + groupPosition + " 已经选中"); notifyDataSetChanged(); } else { //获取子item的数量 int childSize = getChildrenCount(groupPosition); //子Item全都不选中 for (int i = 0; i < childSize; i++) { //获取子item数据 EmployeeEntity child = (EmployeeEntity) getChild(groupPosition, i); child.setIsChecked(false); boolean isLastChild; if (i == childSize - 1) { isLastChild = true; } else { isLastChild = false; } //获得子item View view2 = getChildView(groupPosition, i, isLastChild, null, null); CheckBox childCB = (CheckBox) view2.findViewById(R.id.employee_checkbox); childCB.setChecked(false); System.out.println("子" + groupPosition + "-" + i + " 已经设为没选中"); } parentList.get(groupPosition).setIsChecked(false); notifyDataSetChanged(); } } } ); int childSize = getChildrenCount(groupPosition); List<Boolean> nowChildStatus = new ArrayList<Boolean>(); nowChildStatus.clear(); // cb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { // @Override // public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) { // System.out.println("点击了父" + groupPosition); // if (isChecked) { // //获取子item的数量 // int childSize = getChildrenCount(groupPosition); // //子item全选中 // for (int i = 0; i < childSize; i++) { // //获取子item // EmployeeEntity child = (EmployeeEntity) getChild(groupPosition, i); // child.setIsChecked(true); // boolean isLastChild; // if (i == childSize - 1) { // isLastChild = true; // } else { // isLastChild = false; // } // //获得子item // View view = getChildView(groupPosition, i, isLastChild, null, null); // CheckBox childCB = (CheckBox) view.findViewById(R.id.employee_checkbox); // childCB.setChecked(true); // System.out.println("子" + groupPosition + "-" + i + " 已经选中"); // } // //设置父item被完全选中 // parentList.get(groupPosition).setIsChecked(true); // cb.setChecked(true); // System.out.println("父" + groupPosition + " 已经选中"); // // notifyDataSetChanged(); // } else { // //获取子item的数量 // int childSize = getChildrenCount(groupPosition); // //子Item全都不选中 // for (int i = 0; i < childSize; i++) { // //获取子item数据 // EmployeeEntity child = (EmployeeEntity) getChild(groupPosition, i); // child.setIsChecked(false); // boolean isLastChild; // if (i == childSize - 1) { // isLastChild = true; // } else { // isLastChild = false; // } // //获得子item // View view = getChildView(groupPosition, i, isLastChild, null, null); // CheckBox childCB = (CheckBox) view.findViewById(R.id.employee_checkbox); // childCB.setChecked(false); // System.out.println("子" + groupPosition + "-" + i + " 已经设为没选中"); // } // parentList.get(groupPosition).setIsChecked(false); // // notifyDataSetChanged(); // } // // } // }); // if (parentList.get(groupPosition).getIsChecked() == 2) { // cb.setChecked(true); // } else { // cb.setChecked(false); // } return convertView; } @Override public boolean hasStableIds() { return true; } //子集是否可选 @Override public boolean isChildSelectable(int groupPosition, int childPosition) { return true; } } ```
expandablelistview和checkbox结合使用,复用问题,头疼好几天,大神帮帮忙啊_course
2016-05-15用了viewholder复用了,当子项滑出范围,选中的checkbox变为未选中,不过选中的删除时删除是正确的,只是这样重复选择(不知道怎么说),体验不好,头疼好几天了 expandablelistv
Android 用ExpandableListView 实现二级列表 。。。。_course
2016-11-08这个是打印出来的Log:  这是报错的那行代码
- 怎么实现 ExpandableListActivity with checkbox 6592011-03-15解说一下,这个是个收放的,其次当你选中后再合起来再打开他原来选的还是被默认选中的(这个代码中的处理),希望大家路过的能好好学一下思路,还是很不错的, Log.i("archermind", "---------------------" + s);这句是打印出你所有选中的值。。。package com.android.archermind.activity;import java.util.ArrayList;import java.util.Collection;import java.util.Hash
Android开发丶教你使用ExpandableListView一步步从零实现商城购物车(含demo超详细)下载_course
2020-06-29使用expandable完成电商项目常用的购物车模块,里面涵盖了大部分的常见功能,删除,增减,结算,多店铺多商品的逻辑处理优化,欢迎下载! 相关下载链接://download.csdn.net/dow
ExpandableListView+CheckBox单选的问题,请熟悉的大侠指点下,在线等,多谢啦_course
2014-02-08需求是页面有两个分组:出发城市和目的地,出发城市只能单选一个选项,目的地也只能选一个选项,分别选中后点确定按钮提示所选的内容城市名字,页面图: 我的代码如下: public class MainAct
android listview,ExpandableListView实现单选,多选,全选,edittext实现批量输入.zip下载_course
2020-08-27android listview,ExpandableListView实现单选,多选,全选,edittext实现批量输入.zip 相关下载链接://download.csdn.net/download
515KB
自定义ExpandableListView带CheckBox全选功能
2014-03-18ExpandableListView中group和child自定义视图带CheckBox,实现child全选、部分选中功能,同时实现类似邮件群发的用户选择功能,选中的用户在EditText中显示,点击
515KB
自定义ExpandableListView带CheckBox全选的功能
2018-07-07ExpandableListView中group和child自定义视图带CheckBox,实现child全选、部分选中功能,同时实现类似邮件群发的用户选择功能,选中的用户在EditText中显示,点击
-
博客
计算 java_两种计算Java对象大小的方法objectFieldOffset
计算 java_两种计算Java对象大小的方法objectFieldOffset
-
博客
PHP生成伪随机数
PHP生成伪随机数
-
学院
Windows系统管理
Windows系统管理
-
博客
【花式GIS】QGIS加地图服务
【花式GIS】QGIS加地图服务
-
学院
MySQL 四类管理日志(详解及高阶配置)
MySQL 四类管理日志(详解及高阶配置)
-
学院
MySQL NDB Cluster 负载均衡和高可用集群
MySQL NDB Cluster 负载均衡和高可用集群
-
下载
Linux 串口源代码(纯C++)
Linux 串口源代码(纯C++)
-
学院
linux基础入门和项目实战部署系列课程
linux基础入门和项目实战部署系列课程
-
博客
用高斯混合模型分类三维数据
用高斯混合模型分类三维数据
-
学院
2021年 系统分析师 系列课
2021年 系统分析师 系列课
-
博客
【Mac】mac使用
【Mac】mac使用
-
下载
1997~2018县市社会经济主要指标.rar
1997~2018县市社会经济主要指标.rar
-
学院
自动化测试Python3+Selenium3+Unittest
自动化测试Python3+Selenium3+Unittest
-
博客
【leetcode】组合总和
【leetcode】组合总和
-
学院
朱老师鸿蒙系列课程第1期-3.鸿蒙系统Harmonyos源码配置和管理
朱老师鸿蒙系列课程第1期-3.鸿蒙系统Harmonyos源码配置和管理
-
博客
uniapp组件-uni-tag标签
uniapp组件-uni-tag标签
-
学院
NFS 网络文件系统
NFS 网络文件系统
-
博客
腾讯PCG暑期实习-客户端开发面经
腾讯PCG暑期实习-客户端开发面经
-
学院
零基础极简以太坊智能合约开发环境搭建并开发部署
零基础极简以太坊智能合约开发环境搭建并开发部署
-
下载
自制的mnist数据集
自制的mnist数据集
-
学院
【Python-随到随学】FLask第二周
【Python-随到随学】FLask第二周
-
博客
php实现上传图片保存到数据库的方法
php实现上传图片保存到数据库的方法
-
下载
批量生成条形码和二维码.zip
批量生成条形码和二维码.zip
-
下载
linux c 进程间通信 消息队列
linux c 进程间通信 消息队列
-
下载
STM32F4-3-运行LVGL基础案例.rar
STM32F4-3-运行LVGL基础案例.rar
-
下载
唯恩.rar电气设备选型资料大全 (适合刚刚入行的电气工程师对设备进行选型规划)详解 报价
唯恩.rar电气设备选型资料大全 (适合刚刚入行的电气工程师对设备进行选型规划)详解 报价
-
学院
基于python的dango框架购物商城毕业设计毕设源代码使用教程
基于python的dango框架购物商城毕业设计毕设源代码使用教程
-
博客
Homebrew
Homebrew
-
博客
Windows环境安装DVWA环境
Windows环境安装DVWA环境
-
博客
Git&GitHub入门(MAC)
Git&GitHub入门(MAC)