机器人 - 列表视图过滤器计数 [英] android - listview filter count

查看:152
本文介绍了机器人 - 列表视图过滤器计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,当我设置我的列表视图过滤器:

So after I set the filter on my listview:

//Log adapter count before filter
listView.getFilter().filter(searchStr)
//Log adapter count after filter

我试图做到的,是得到了过滤的结果的数量。就像如果之前已经有10个项目,那么我应用滤镜,所以现在只有5个项目会出现,我想那算不算5。我已经试过前和过滤器,没有运气后检查适配器数量。他们显示相同的数(我使用BaseExpandableListAdapter),如果我申请过滤器,如果我再次申请过滤从之前数变化(但前和过滤后仍然是相同的)。

What I'm trying to achieve is to get the count of the result of that filtering. Like if before there are 10 items, then I apply the filter, so now only 5 items will appear, I want to get that count "5". I've tried checking the adapter count before and after the filter with no luck. They're displaying same count (I'm using a BaseExpandableListAdapter) if I apply filter, and if I apply filter again the number changes from before (but the before and after of filter is still the same).

下面是一个样本结果是什么,我让我的日志:

Below is a sample result of what I'm getting on my logs:

Before filter the count is 10. After filter the count is 10.
Before filter the count is 8.  After filter the count is 8.

我想,也许我的适配器没有得到体现伯爵马上,但在第二个过滤器,它改变了价值,所以我想过滤后notifyDataSetChanged会有所作为,但事实并非如此。任何帮助将是AP preciated。

I thought maybe my adapter doesn't get the reflected count right away but on the second filter, it changes the value, so I thought notifyDataSetChanged after the filter would make a difference, but it did not. Any help would be appreciated.

感谢。

推荐答案

这是我如何设法做到这一点:

This is how I managed to do it:

myAdapter.getFilter().filter(searchText, new Filter.FilterListener() {
    public void onFilterComplete(int count) {
         Log.d("log", "result count:" + count);
    }
}

这篇关于机器人 - 列表视图过滤器计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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