FlexibleAdapter
FlexibleAdapter copied to clipboard
Keep filtering items after adapter.updateDataSet(data)
I have a list with items that I filter. Then I want to load new items from server, before that I call adapter.updateDataSet(null) to clear list. When I receive data from server I am setting them to adapter with 'adapter.updateDataSet(data)' and it is showing all items without filtering. When I call adapter.getFilter(String.class) before and after inserting items it returns my filter string and if I call adapter.filterItems(), after inserting them, nothing happens. How to persist my filter when updating data set?
What am I doing wrong?
@jurisjansons, are you trying to update the data set with a new one not filtered and then trying to filter?
Why not providing a data set already filtered?
Currently, the update of a data set does not take into account the filter in memory.
However, the reason you don't see it filtered (by calling filterItems just after the update) could be because the filter string didn't change so it skips the elaboration, but if you clear it, it will try to restore the original list first!!
Could you please describe better your use case?
@jurisjansons, it might be margin for an improvement, I need to understand. Could you please answer at my questions above? Thanks.
@davideas Sorry for late response, didn't get first notification about comment. Yes, I am updating data set with new data set and then want to apply filter that is already defined in adapter, so I am not changing it. I guess it skips filtering as you said, because filter hasn't changed. I think calling filterItems should check for both, data set change and filter string change.
Provide already filtered data set? Doesn't it mean that I won't be able to clear filter and show unfiltered data set when changing or clearing filter?
It might be part of the same enhancement of #675. The logic to set or update new items is in common. The improvement should take into account the existing filter when new items or configuration changes occur.
It should be fairly easy: I will analyse it.
Hi,
Have you found a tricks ? I'm trying to do the same things keep my filter applied after a « pull to refresh » without filter my data on the backend side.
I have decided to use library as a local module and added necessary function myself
import library as local module and add just following Function in FlexibleAdapter Class,
public void resetFilter() { mOldFilterEntity = null; mFilterEntity = null; }
if you want update or sort your data set and set previos filter again , the code should be look like as following,
resetFilter(); filterItems(); updateDataSet(sortedData); setFilter(prevFilter); filterItems();