As data sources provide new instances of
PagedList, the activity sends
these objects to the adapter. The
PagedListAdapter
implementation defines how updates are computed, and it automatically handles
paging and list diffing. Therefore, your
ViewHolder
only needs to bind to a particular provided item:

Note:PagedList is
content-immutable. This means that, although new content can be loaded into an
instance of PagedList, the loaded items themselves cannot change once loaded.
As such, if content in a PagedList updates, the
PagedListAdapter object
receives a completely new PagedList that contains the updated information.

Implement the diffing callback

The following sample shows a manual implementation of
areContentsTheSame(),
which compares relevant object fields:

Because your adapter includes your definition of comparing items, the adapter
automatically detects changes to these items when a new PagedList object is
loaded. As a result, the adapter triggers efficient item animations within your
RecyclerView object.

Diffing using a different adapter type

If you choose not to inherit from
PagedListAdapter—such as
when you're using a library that provides its own adapter—you can still use the
Paging Library adapter's diffing functionality by working directly with an
AsyncPagedListDiffer
object.

Provide placeholders in your UI

In cases where you want your UI to display a list before your app has finished
fetching data, you can show placeholder list items to your users. The
PagedList handles this case by
presenting the list item data as null until the data is loaded.

Note: By default, the Paging Library enables this placeholder behavior.

Placeholders have the following benefits:

Support for scrollbars: The
PagedList provides the number of
list items to the
PagedListAdapter. This
information allows the adapter to draw a scrollbar that conveys the full size of
the list. As new pages load, the scrollbar doesn't jump because your list
doesn't change size.

No loading spinner necessary: Because the list size is already known,
there's no need to alert users that more items are loading. The placeholders
themselves convey that information.

Before adding support for placeholders, though, keep the following
preconditions in mind:

Requires adapter to account for unloaded items: The adapter or
presentation mechanism that you use to prepare the list for inflation needs to
handle null list items. For example, when binding data to a
ViewHolder,
you need to provide default values to represent unloaded data.

Requires same-sized item views: If list item sizes can change based on
their content, such as social networking updates, crossfading between items
doesn't look good. We strongly suggest disabling placeholders in this case.