{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

Pager

public final class Pager<Key extends Object, Value extends Object>


Primary entry point into Paging; constructor for a reactive stream of PagingData.

Each PagingData represents a snapshot of the backing paginated data. Updates to the backing dataset should be represented by a new instance of PagingData.

PagingSource.invalidate and calls to AsyncPagingDataDiffer.refresh or PagingDataAdapter.refresh will notify Pager that the backing dataset has been updated and a new PagingData / PagingSource pair will be generated to represent an updated snapshot.

PagingData can be transformed to alter data as it loads, and presented in a RecyclerView via AsyncPagingDataDiffer or PagingDataAdapter.

LiveData support is available as an extension property provided by the androidx.paging:paging-runtime artifact.

RxJava support is available as extension properties provided by the androidx.paging:paging-rxjava2 artifact.

import androidx.paging.insertSeparators

/*
 * Create letter separators in an alphabetically sorted list.
 *
 * For example, if the input is:
 *     "apple", "apricot", "banana", "carrot"
 *
 * The operator would output:
 *     "A", "apple", "apricot", "B", "banana", "C", "carrot"
 */
pagingDataStream.map { pagingData ->
    // map outer stream, so we can perform transformations on each paging generation
    pagingData.insertSeparators { before: String?, after: String? ->
        if (after != null && before?.first() != after.first()) {
            // separator - after is first item that starts with its first letter
            after.first().toUpperCase().toString()
        } else {
            // no separator - either end of list, or first letters of before/after are the same
            null
        }
    }
}

Summary

Public constructors

@<Error class: unknown class>
@OptIn(markerClass = )
<Key extends Object, Value extends Object> Pager(
    @NonNull <Error class: unknown class> config,
    Key initialKey,
    @NonNull Function0<@NonNull <Error class: unknown class><@NonNull Key, @NonNull Value>> pagingSourceFactory
)
@<Error class: unknown class>
<Key extends Object, Value extends Object> Pager(
    @NonNull <Error class: unknown class> config,
    Key initialKey,
    <Error class: unknown class><@NonNull Key, @NonNull Value> remoteMediator,
    @NonNull Function0<@NonNull <Error class: unknown class><@NonNull Key, @NonNull Value>> pagingSourceFactory
)

Public methods

final @NonNull <Error class: unknown class><@NonNull PagingData<@NonNull Value>>

A cold Flow of PagingData, which emits new instances of PagingData once they become invalidated by PagingSource.invalidate or calls to AsyncPagingDataDiffer.refresh or PagingDataAdapter.refresh.

Public constructors

Pager

@<Error class: unknown class>
@OptIn(markerClass = )
public <Key extends Object, Value extends Object> Pager(
    @NonNull <Error class: unknown class> config,
    Key initialKey,
    @NonNull Function0<@NonNull <Error class: unknown class><@NonNull Key, @NonNull Value>> pagingSourceFactory
)

Pager

@<Error class: unknown class>
public <Key extends Object, Value extends Object> Pager(
    @NonNull <Error class: unknown class> config,
    Key initialKey,
    <Error class: unknown class><@NonNull Key, @NonNull Value> remoteMediator,
    @NonNull Function0<@NonNull <Error class: unknown class><@NonNull Key, @NonNull Value>> pagingSourceFactory
)
Parameters
@NonNull <Error class: unknown class> config

The configuration

Public methods

getFlow

public final @NonNull <Error class: unknown class><@NonNull PagingData<@NonNull Value>> getFlow()

A cold Flow of PagingData, which emits new instances of PagingData once they become invalidated by PagingSource.invalidate or calls to AsyncPagingDataDiffer.refresh or PagingDataAdapter.refresh.