Android的ListView中的复选框全部选中(禁用/启用) [英] Android Checkbox listview select all (disable/enable)

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

问题描述

我想禁用/启用列表视图所有复选框。 INFACT想通过单击上面的复选框选择所有的行为。

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

感谢

推荐答案

这是什么终于为我工作,在这里我使用游标适配器,不只是一个 ArrayListAdapter 我的列表项:

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 不工作,因为它似乎只能算什么被立即拉(并非所有的关闭屏幕),所以 childCount 可能只6或8个项目时整个列表是100或更多的项目。另外,作为我不得不使用 list.setItemChecked 获得的项目检查保持 - 至少在我的情况下,我的列表中的项目均 CheckedTextView 。

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的ListView中的复选框全部选中(禁用/启用)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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