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

查看:21
本文介绍了获取所有 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 items(rows) 代替.我怎样才能做到这一点?
我正在做的是将选定的 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天全站免登陆