Pagination with Paging library in Android

Updated 6 September 2019

Save

The Paging library is a part of Android Jet Pack. It will help you load and display small chunks of data at a time. Loading partial data on demand reduces the usage of network bandwidth and system resources.

For this, we will require to add the following dependencies in the project’s build.gradle file:

The Paging Library’s key component is the PagedList class, which loads chunks of your app’s data, or pages. As more data is needed, it’s paged into the existing PagedList object. If any loaded data changes then a new instance of PagedList is emitted to the observable data holder from a PagedList or RxJava2-based object. As PagedList objects are generated, your app’s UI presents their contents, all while respecting your UI controllers’ lifecycle.

Gathering paged data

We can define our own paging configuration. Like the items per page and prefetched items count and many more things. And then get the data by network call or local database.

Display paged lists

Connect your UI to your view model. You can connect an instance of  LiveData<PagedList> to a PagedListAdapter, as shown in the following code snippet:

References:

author
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Start a Project


    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home