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

LazyPagingItems

{% setvar page_path %}androidx/paging/compose/LazyPagingItems.html{% endsetvar %} {% setvar can_switch %}1{% endsetvar %} {% include "reference/_java_switcher2.md" %}

public final class LazyPagingItems<T extends Object>


The class responsible for accessing the data from a Flow of PagingData. In order to obtain an instance of LazyPagingItems use the collectAsLazyPagingItems extension method of Flow with PagingData. This instance can be used by the items and itemsIndexed methods inside LazyListScope to display data received from the Flow of PagingData.

Parameters
<T extends Object>

the type of value used by PagingData.

Summary

Public fields

final int

The number of items which can be accessed.

final @NonNull CombinedLoadStates

A CombinedLoadStates object which represents the current loading state.

Public methods

final @Nullable T
get(int index)

Returns the item specified at index and notifies Paging of the item accessed in order to trigger any loads necessary to fulfill PagingConfig.prefetchDistance.

final @Nullable T
peek(int index)

Returns the presented item at the specified position, without notifying Paging of the item access that would normally trigger page loads.

final void

Refresh the data presented by this LazyPagingItems.

final void

Retry any failed load requests that would result in a LoadState.Error update to this LazyPagingItems.

final @NonNull ItemSnapshotList<@NonNull T>

Returns a new ItemSnapshotList representing the currently presented items, including any placeholders if they are enabled.

Public fields

itemCount

@NonNull
public final int itemCount

The number of items which can be accessed.

loadState

@NonNull
public final @NonNull CombinedLoadStates loadState

A CombinedLoadStates object which represents the current loading state.

Public methods

get

@Nullable
public final T get(int index)

Returns the item specified at index and notifies Paging of the item accessed in order to trigger any loads necessary to fulfill PagingConfig.prefetchDistance.

Parameters
int index

the index of the item which should be returned.

Returns
T

the item specified at index or null if the index is not between correct bounds or the item is a placeholder.

peek

@Nullable
public final T peek(int index)

Returns the presented item at the specified position, without notifying Paging of the item access that would normally trigger page loads.

Parameters
int index

Index of the presented item to return, including placeholders.

Returns
T

The presented item at position index, null if it is a placeholder

refresh

@NonNull
public final void refresh()

Refresh the data presented by this LazyPagingItems.

refresh triggers the creation of a new PagingData with a new instance of PagingSource to represent an updated snapshot of the backing dataset. If a RemoteMediator is set, calling refresh will also trigger a call to RemoteMediator.load with REFRESH to allow RemoteMediator to check for updates to the dataset backing PagingSource.

Note: This API is intended for UI-driven refresh signals, such as swipe-to-refresh. Invalidation due repository-layer signals, such as DB-updates, should instead use PagingSource.invalidate.

See also
PagingSource.invalidate

retry

@NonNull
public final void retry()

Retry any failed load requests that would result in a LoadState.Error update to this LazyPagingItems.

Unlike refresh, this does not invalidate PagingSource, it only retries failed loads within the same generation of PagingData.

LoadState.Error can be generated from two types of load requests:

snapshot

@NonNull
public final ItemSnapshotList<@NonNull T> snapshot()

Returns a new ItemSnapshotList representing the currently presented items, including any placeholders if they are enabled.