Rade
Rade

Reputation: 320

Paging library - Can't stop loading items

I'm using Paging library to load date directly from network. Do I have to implement logic to stop fetching data? In my case, that can be when received item count is lower than page size. Currently when I reach end of list lib keeps loading new pages.

Upvotes: 7

Views: 5244

Answers (1)

EpicPandaForce
EpicPandaForce

Reputation: 81539

Theoretically, PageKeyedDataSource has a result callback,

PageKeyedDataSource.LoadCallback

And that has an onResult method, where the docs says

Pass an empty list if there is no more data to load.

Pass the key for the subsequent page to load to adjacentPageKey. For example, if you've loaded a page in loadBefore(LoadParams, LoadCallback), pass the key for the previous page, or null if the loaded page is the first. If in loadAfter(LoadParams, LoadCallback), pass the key for the next page, or null if the loaded page is the last.

So it says you should pass an empty list, and null for adjacent page key, and it should work.

Upvotes: 12

Related Questions