选择在ListView中的所有项目 [英] Select all items within ListView

查看:133
本文介绍了选择在ListView中的所有项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前工作的一个Android项目。我使用的是ListView和使用上下文操作栏,我成功地选择每个项目,显示了有多少项目已经在列表视图中选择一个计数。

I am currently working on an android project. I am using a ListView and using a context action bar and I am sucessfully selecting each item and showing a count of how many items have been selected within the list view.

在上下文吧我有菜单选项全选,但我不知道我怎么能确保该列表视图中的每一个项目被选中。

Within the context bar I have a menu option for Select All but I don't know how I can make sure that every item within the list view is selected.

似乎无法找到任何关于谷歌,任何关于这种类型的东西和可选列表视图似乎是很好的隐藏。

Can't seem to find anything on Google, anything about this type of thing and selectable ListViews seem to be very well hidden.

任何帮助将是很大的AP preciated。

Any help would be greatly appreciated.

感谢您

推荐答案

您可以检查列表视图项目一个接一个:

You can check listview items one by one:

for ( int i=0; i < listview.getAdapter().getCount(); i++) {
   listview.setItemChecked(i, true);
}

如果你只需要选择的是在屏幕上,然后用 listview.getChildCount()

If you only want to select what is on screen, then use listview.getChildCount().

如果您使用的是片段,你需要使用 getListAdapter()。getCount将()

If you are using fragments, you will need to use getListAdapter().getCount().

这篇关于选择在ListView中的所有项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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