public abstract class ItemKeyedDataSource<Key extends Object, Value extends Object> extends DataSource

   ↳ DataSource
     ↳ ItemKeyedDataSource

Incremental data loader for paging keyed content, where loaded content uses previously loaded items as input to future loads.

Implement a DataSource using ItemKeyedDataSource if you need to use data from item N - 1 to load item N. This is common, for example, in uniquely sorted database queries where attributes of the item such just before the next query define how to execute it.

The InMemoryByItemRepository in the PagingWithNetworkSample shows how to implement a network ItemKeyedDataSource using Retrofit, while handling swipe-to-refresh, network errors, and retry.

<Key extends Object>

Type of data used to query Value types out of the DataSource.

<Value extends Object>

Type of items being loaded by the DataSource.


Nested types


Callback for ItemKeyedDataSource loadBefore and loadAfter to return data.


Callback for loadInitial to return data and, optionally, position/count information.


Holder object for inputs to loadInitial.


Holder object for inputs to loadBefore and loadAfter.

Public constructors

<Key extends Object, Value extends Object> ItemKeyedDataSource()

Public methods

abstract @NonNull Key
getKey(Value item)

Return a key associated with the given item.

abstract void
    ItemKeyedDataSource.LoadParams<Key> params,
    ItemKeyedDataSource.LoadCallback<Value> callback

Load list data after the key specified in LoadParams.key.

abstract void
    ItemKeyedDataSource.LoadParams<Key> params,
    ItemKeyedDataSource.LoadCallback<Value> callback

Load list data before the key specified in LoadParams.key.

abstract void

Load initia