5

I am learning android paging library and everything works perfectly. But whenever I invalidate the DataSource, the list is jumping to start position whenever a new item is added to the top of the list. I want to the list to add the item to top. But the list should stay in its current scrolling position. I think I should use LoadInitialParams.requestedInitialKey which is not null when invalidating. But am not sure how to use this key to load data to avoid jumping of list to start position.

I am using firestore database as data source. I found that the requestedInitialKey supplied to the callback is actually the last visible item in the recyclerview in current scrolling position. I have already tried the following to fetch data around the requestedInitialKey

.get().startAt(requestedIntitalKey).limit(25)

.get().endBefore(requestedIntitalKey).limit(25)

.get().startAfter(requestedIntitalKey).limit(25)

.get().endAt(requestedIntitalKey).limit(25)

where 25 is my page size. None of the above solved the problem. Can someone provide me with an example so that the list will stay at its current scrolling position only updating the content without jumping to start?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Sundaravel
  • 464
  • 5
  • 16

0 Answers0