Android 复选框列表视图全选(禁用/启用) [英] Android Checkbox listview select all (disable/enable)

查看:34
本文介绍了Android 复选框列表视图全选(禁用/启用)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想禁用/启用列表视图中的所有复选框.事实上想要通过点击顶部复选框来选择所有行为.

谢谢

解决方案

这最终对我有用,我使用的是游标适配器,而不仅仅是列表项的 ArrayListAdapter:

final ListView list = getListView();for ( int i=0; i< getListAdapter().getCount(); i++ ) {list.setItemChecked(i, true);}

list.getChildCount 不起作用,因为它似乎只计算立即绘制的内容(不是屏幕外的所有内容),所以 childCount 可能只有 6 或 8当整个列表为 100 个或更多项目时.此外,因为我不得不使用 list.setItemChecked 来让项目保持检查状态"——至少在我的列表项目是 CheckedTextView 实例的情况下.>

I want to disable/enable all checkboxes in listview. infact want to get select all behaviour by clicking on top checkbox.

thanks

解决方案

This is what finally worked for me, where I'm using a cursor adapter, not just an ArrayListAdapter for my list items:

final ListView list = getListView();
for ( int i=0; i< getListAdapter().getCount(); i++ ) {
        list.setItemChecked(i, true);
}

list.getChildCount doesn't work because it only seems to count what's been drawn immediately (not everything that's off the screen) so childCount might only be 6 or 8 items when the entire list is 100 or more items. Also as I had to use list.setItemChecked to get the items to 'stay checked' -- at least in my case where my list items were instances of CheckedTextView.

这篇关于Android 复选框列表视图全选(禁用/启用)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆