FlexibleAdapter icon indicating copy to clipboard operation
FlexibleAdapter copied to clipboard

Keep filtering items after adapter.updateDataSet(data)

Open jurisjansons opened this issue 7 years ago • 7 comments
trafficstars

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 avatar Oct 25 '18 16:10 jurisjansons

@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?

davideas avatar Oct 26 '18 14:10 davideas

@jurisjansons, it might be margin for an improvement, I need to understand. Could you please answer at my questions above? Thanks.

davideas avatar Dec 11 '18 08:12 davideas

@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?

jurisjansons avatar Dec 11 '18 10:12 jurisjansons

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.

davideas avatar Mar 20 '19 09:03 davideas

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.

c4software avatar Oct 18 '19 17:10 c4software

I have decided to use library as a local module and added necessary function myself

NLLAPPS avatar Oct 18 '19 19:10 NLLAPPS

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

burakremzisenel avatar Jul 12 '22 11:07 burakremzisenel