Closed hannta closed 4 years ago
@hannta in general the question is mainly related to the RecyclerView
as the adapter only serves as providing instance. e.g. provides the elements to the RecyclerView, notifies about changes in the set of data.
You could try to scroll the the according location again? e.g. use the recyclerView API to scrollTo without animation as soon as you changed the data. (this might get a bit tricky with the DiffUtil as it does things async and updates only changed elements) but it might be it already :)
Thanks @mikepenz! I tried to avoid manually setting RecyclerView
scroll position, but looks like it is the only way forward.
I managed to get this somewhat working, setting scroll position via layout manager like (recyclerview.layoutManager as LinearLayoutManager).scrollToPositionWithOffset(position, 0)
. Looks like it works with DiffUtil
too, even it is not inserting/updating items synchronously(?). Or maybe my test list is just too small, and DiffUtil
is quick enough to update the items.
Perhaps the RV is clever enough to handle this luckily ☺️
I try to build list with header and footer. When the header is clicked, new items are added to top and with footer click items added to bottom. I use
FastAdapterDiffUtil
to set items.My FastAdapter is setup like this:
When I set new items to
itemsModelAdapter
is use DiffUtil:The problem:
When I add new items to top of the list (in
itemsModelAdapter
), I want to keep the list scrolling position (in terms of items initemsModelAdapter
) unchanged. So push header up with new items initemsModelAdapter
.What happens is that header is kept in first visible item in recyclew view, and all items are added below that. So for user it looks like all old items are pushed down.
How could I ignore header item from this recycler view scroll logic, and push it up?
With out header item, the recycler view works like I want, items are added to top of the list, and current scroll position is not changed. Maybe I should try to remove header item before adding new items and restore it afterward, that sound bit hackish though.
Sorry if this question is more related to recycler view itself than FastAdapter, but sometimes these goes pretty tightly hand in hand 😊