安卓:获取可见子的数量在ListView [英] Android: Getting a count of the visible children in a listview

查看:362
本文介绍了安卓:获取可见子的数量在ListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

时有办法让可见光列表视图的儿童人数的计数?

Is there are way to get a count of the number of visible listview children?

我有信息链接到可以在任何时候更改数据库列表视图。当数据库发生变化时,我发出广播通知UI类处理列表视图。有关更改的数据的子元素被更新。我通过给每个ListView项标签,然后遍历列表视图找到该行从广播相匹配的标签实现这一目标。

I have a listview with info linked to a database that can change at any time. When the database is changed, I send out a broadcast notifying the ui class handling the list view. The child element relating to the changed data is then updated. I am achieving this by giving each listview item a tag, and then iterating over the listviews to find the row matching the tag from the broadcast.

我只想迭代可见子。没有必要对我来说,手动更新的观点是不可见的,因为他们将反映新数据被创建时。我目前遍历从listView.getfirstVisiblePosition()来listView.getChildCount()。这比没有好,因为我不检查以上可见行的行,但我不希望检查他们下面的行无论是。

I want to only iterate over the visible children. There is no need for me to manually update views that are not visible, as they will reflect the new data when they are created. I currently iterate from listView.getfirstVisiblePosition() to listView.getChildCount(). This is better than nothing, as I don't examine rows above the visible rows, but I don't want to examine the rows below them either.

我查了Android开发ListView的页面,并没有发现任何东西。任何人都知道的一种方式我可以看到孩子的数量?

I checked the android developers listView page and didn't find anything. Anyone know of a way I can get the count of visible children?

谢谢!

推荐答案

listView.getLastVisiblePosition(),这是你在找什么?如果不, 通过子视图迭代...

listView.getLastVisiblePosition(), is this what you are looking for? if not, Iteration through child views...

int count = 0;

for (int i = 0; i <= listView.getLastVisiblePosition(); i++)
{
    if (listView.getChildAt(i) != null)
    {
        count++;  // saying that view that counts is the one that is not null, 
                  // because sometimes you have partially visible items....
    }
}

这篇关于安卓:获取可见子的数量在ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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