Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android - listview filter count

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.

like image 600
lorraine Avatar asked Jan 31 '13 14:01

lorraine


1 Answers

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);
    }
});
like image 123
lorraine Avatar answered Oct 18 '22 01:10

lorraine