android - listview filter count

百般思念 提交于 2019-12-18 13:11:54

问题


So after I set the filter on my listview:

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

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.

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.

Thanks.


回答1:


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);
    }
});



回答2:


Try calling listview.getCount() after applying the filter.



来源:https://stackoverflow.com/questions/14628453/android-listview-filter-count

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!