dvdciri / MultiChoiceRecyclerView

Multi choice selection applied on recycler view make life easier

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

If updating adapter item list later on through notifyDataSetChanged, invalid state

dvdciri opened this issue · comments

Context

When passing an empty list to the adapter and updating the last later on, through notifyDataSetChanged, the adapter will end up saving not all the list of items, but only the one that are bind to a view (because of the internal logic of the MultiChoiceAdapter). This is putting the app in an invalid state because when we go to selectAll items, for instance, the MultiChoiceAdapter knows only about those binded items and not the non-binded ones.

Possible solution

It might be necessary to ask the user in the MultiChoiceAdapter constructor or somewhere else, maybe forcing it through an abstract method, to provide the item size list.

Or it might just work that when we found an item not in the list of items, we re-call getItemCount() method of the Adapter and re-init the list the new INACTIVE items.

@dvdciri I tried your library and noticed that if the recycler view starts empty and then later I update the list and call notifyDataSetChanged i can't multiple select any items on my list. I suppose this problem is related with this issue? I really need this to be fixed since the recycler view is updated with a remote call to an api server

Yes, correct, this is the issue for that. I'll be working on this soon providing a method to refresh the data set, and setting all of the item to UNSELECTED. Does it make sense?

@dvdciri I will try to fix the issue on your library then

That would be good, though i already started doing that.. so i'd say let me do this and you can review it if you want. =)

@dvdciri Okay hurry up then 👍

@dvdciri Nice i also managed to fix the issue my self let me check your fix to see if i did the same approach

I need this fix to go in master because it is also fixing some other issues. So from now on if you want to notify that the data set has changed you should use MultiChoiceAdapter#refreshDataSet().

I'm gonna put that into the README documentation as well.