public class AsyncPagedListDiffer<T extends Object>

Helper object for mapping a androidx.paging.PagedList into a RecyclerView.Adapter.

For simplicity, the PagedListAdapter wrapper class can often be used instead of the differ directly. This diff class is exposed for complex cases, and where overriding an adapter base class to support paging isn't convenient.

When consuming a LiveData of PagedList, you can observe updates and dispatch them directly to submitList. The AsyncPagedListDiffer then can present this updating data set simply for an adapter. It listens to PagedList loading callbacks, and uses DiffUtil on a background thread to compute updates as new PagedLists are received.

It provides a simple list-like API with getItem and itemCount for an adapter to acquire and present data objects.

A complete usage pattern with Room would look like this:

interface UserDao {
@Query("SELECT * FROM user ORDER BY lastName ASC")
public abstract DataSource.Factory<Integer, User> usersByLastName();

class MyViewModel extends ViewModel {
public final LiveData<PagedList<User>> usersList;
public MyViewModel(UserDao userDao) {
usersList = new LivePagedListBuilder<>(
userDao.usersByLastName(), /* page size */20).build();

class MyActivity extends AppCompatActivity {
public void onCreate(Bundle savedState) {
MyViewModel viewModel = new ViewModelProvider(this).get(MyViewModel.class);
RecyclerView recyclerView = findViewById(;
final UserAdapter adapter = new UserAdapter();
viewModel.usersList.observe(this, pagedList -> adapter.submitList(pagedList));

class UserAdapter extends RecyclerView.Adapter&lt;UserViewHolder> {
private final AsyncPagedListDiffer&lt;User> differ =
new AsyncPagedListDiffer(this, DIFF_CALLBACK);
public int getItemCount() {
return differ.getItemCount();
public void submitList(PagedList&lt;User> pagedList) {
public void onBindViewHolder(UserViewHolder holder, int position) {
User user = differ.getItem(position);
if (user != null) {
} else {
// Null defines a placeholder item - AsyncPagedListDiffer will automatically
// invalidate this row when the actual object is loaded from the database
public static final DiffUtil.ItemCallback&lt;User> DIFF_CALLBACK =
new DiffUtil.ItemCallback&lt;User>() {
public boolean areItemsTheSame(
@NonNull User oldUser, @NonNull User newUser) {
// User properties may have changed if reloaded from the DB, but ID is fixed
return oldUser.getId() == newUser.getId();
public boolean areContentsTheSame(@NonNull User oldUser, @NonNull User newUser) {
// NOTE: if you use equals, your object must properly override Object#equals()
// Incorrectly returning false here will result in too many animations.
return oldUser.equals(newUser);
<T extends Object>

Type of the PagedLists this differ will receive.


Nested types


This interface is deprecated. PagedList is deprecated and has been replaced by PagingData

Public fields

@Nullable PagedList<@NonNull T>

Returns the PagedList currently being displayed by the differ.


Get the number of items currently presented by this Differ.

Public constructors

<T extends Object> AsyncPagedListDiffer(
    @NonNull RecyclerView.Adapter<@NonNull ?> adapter,
    @NonNull DiffUtil.ItemCallback<@NonNull T> diffCallback

Convenience for

<T extends Object> AsyncPagedListDiffer(
    @NonNull ListUpdateCallback listUpdateCallback,
    @NonNull AsyncDifferConfig<@NonNull T> config

Public methods

    @NonNull Function2<@NonNull LoadType, @NonNull LoadStateUnit> listener

Add a LoadState listener to observe the loading state of the current PagedList.


Add a PagedListListener to receive updates when the current PagedList changes.

final void
    @NonNull Function2<@NonNull PagedList<@NonNull T>, @NonNull PagedList<@NonNull T>, Unit> callback

Add a callback to receive updates when the current PagedList changes.

@Nullable T
getItem(int index)

Get the item from the current PagedList at the specified index.


Remove a previously registered LoadState listener.


Remove a previously registered PagedListListener.

final void

Remove a previously registered callback via addPagedListListener.


Pass a new PagedList to the differ.

    @Nullable PagedList<@NonNull T> pagedList,
    @Nullable Runnable commitCallback

Pass a new PagedList to the differ.

Public fields


public @Nullable PagedList<@NonNull T> currentList

Returns the PagedList currently being display