获取所有ListView项(行) [英] Get all ListView items(rows)

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

问题描述

我如何获得ListView项的所有子项?
有一些方法可以让孩子处于适当的位置,但是我找不到任何方法返回ListView项目中所有孩子的集合.

How may I get all children of an item of ListView ?
There are methods to get child at position but I was not able to find any method which returns collection of all children in an item of ListView.

更新:我只是发现我需要ListView个项目(行).我该如何实现?
我正在做的是将选定的ListView项目与所有项目进行比较.

Update : I just found out that I need ListView items(rows) instead. How may I achieve this ?
What I am doing is, comparing the selected ListView item with all items.

推荐答案

您可以通过迭代从列表适配器中获取所有列表项,如下所示:

You get all list item from list adapter through iteration as below

for (int i=0;i<adapter.getCount();i++){
     adapter.getItem(i);
}

更新:您可以使用索引将特定项目与列表适配器进行比较,如下所示:

Update : You can compare specific item using index with list adapter all items as below :

for (int i=0;i<adapter.getCount();i++){
    if(adapter.get(selectedIndex)==adapter.getItem(i)){
       // TODO : write code here item match 
       break; // after match is good practice to break loop instead compare rest of item even match
    }
}

这篇关于获取所有ListView项(行)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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