1

I have a RecyclerView with a PagedListAdapter which is used to show a list of text(such as 0,1,2,...,99), and there is a button to add 20 more items to database such that the list of text becomes (0,1,2,...,99,...,119).

With page size equals to 20, the list can load 20 items page to page (where datasource.loadAfter() is triggered) when scrolling the list.

When the list hasn't scrolled to bottom and I click the button, new items are added, and scrolled down to bottom, datasource.loadAfter() is triggered, new items are displayed.

However, when the list has reached bottom and I click the button, new items are added to database but datasource.loadAfter() is not triggered, and those new items are not shown on display.

What can I do to make new items shown when the list already reached bottom?

As I have posted codes in other question, so I just post the link here: The code I used

Season
  • 1,178
  • 2
  • 22
  • 42
  • you have to `invalidate()` your `DataSource` – pskink Oct 20 '18 at 07:01
  • @pskink if I called invalidate(), the list will be reloaded from begining, and the scroll position before add item cannot be maintained, how can I maintain the scroll position? – Season Oct 20 '18 at 07:45
  • it will be preserved, try for example to use `room` and insert some rows and you will see that the scroll position is not reset to zero - for updating the data see [DataSource](https://developer.android.com/reference/android/arch/paging/DataSource) documentation and ^F `Updating Paged Data` – pskink Oct 20 '18 at 07:48
  • @pskink what if I don't use Room? – Season Oct 20 '18 at 07:50
  • it does not matter what `DataSource` you use - i mentioned `room` since it has everything "out-of-the-box" – pskink Oct 20 '18 at 07:50
  • @pskink however, scroll position does n't maintained when invalidate() is called. I have tried that before. Is there something wrong in my code? – Season Oct 20 '18 at 07:57
  • yes: your `DIFF_CALLBACK` is wrong, see [PagedListAdapter](https://developer.android.com/reference/android/arch/paging/PagedListAdapter) for some hints – pskink Oct 20 '18 at 07:59
  • @pskink which part is wrong? I currently compare string content to see them as different . – Season Oct 20 '18 at 08:02
  • @pskink yes, I've read that before. As my list of string are having unique content and order will not be changed, so I just compare their content to serve as comparing id as in the link's example. – Season Oct 20 '18 at 08:12

0 Answers0