I have ListView with custom adapter extends ArrayAdapter. Each item is object:
public class ListItemObject {
public String messageText;
public long messageTime;
public long fromId;
public long toId;
}
I want to add checkable item in menu for filtering switching. So when this item unchecked I will show all items, and when this item checked ListView must contain only filtered items with this condition:
if(fromId==myId || toId==myId) {
//show item
} else {
//don't show item
}
I see two ways to implement this:
-
Make my own filter extends Filter. Then call adapter.getFilter().filter(string_with_fromId_and_toId_in_JSON). I see one problem here: to all appearance adapter can contain only one filter. And if I want to add another filter in future, I can’t do it.
-
Save all items outside the adapter, clear it and fill again with filtered data. That is not convenient method for me, but I can do it.
How to better to implement this?
I have used both. I created a flag like
FILTER_BY_CUSTOM_COLLECTIONand send it to filter function asconstraintparameter. If constraint is equal to my flag I do my custom filter else I use that constraint as a real text constraint:in my filter: