Android 12 Developer Preview is here! Try it out, and give us your feedback!

ItemKeyedDataSource

abstract class ItemKeyedDataSource<Key : Any, Value : Any> : DataSource<Key, Value>
kotlin.Any
   ↳ androidx.paging.DataSource<Key, Value>
   ↳ androidx.paging.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.

Summary

Nested classes
abstract

Callback for ItemKeyedDataSource loadBefore and loadAfter to return data.

abstract

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

open

Holder object for inputs to loadInitial.

open

Holder object for inputs to loadBefore and loadAfter.

Public constructors

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

Public methods
abstract Key
getKey(item: Value)

Return a key associated with the given item.

abstract Unit

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

abstract Unit

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

abstract Unit

Load initial data.

ItemKeyedDataSource<Key, ToValue>
map(function: Function<Value, ToValue>)

Applies the given function to each value emitted by the DataSource.

ItemKeyedDataSource<Key, ToValue>
map(function: (Value) -> ToValue)

Applies the given function to each value emitted by the DataSource.

ItemKeyedDataSource<Key, ToValue>
mapByPage(function: Function<List<Value>, List<ToValue>>)

Applies the given function to each value emitted by the DataSource.

ItemKeyedDataSource<Key, ToValue>
mapByPage(function: (List<Value>) -> List<ToValue>)

Applies the given function to each value emitted by the DataSource.

Inherited functions
Inherited properties

Public constructors

<init>

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.

Parameters
Key Type of data used to query Value types out of the DataSource.
Value Type of items being loaded by the DataSource.

Public methods

getKey