{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}
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 |
Public fields |
|
---|---|
final int |
The number of items which can be accessed. |
final @NonNull CombinedLoadStates |
A |
Public methods |
|
---|---|
final @Nullable T |
get(int index) Returns the item specified at |
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() Refresh the data presented by this |
final void |
retry() Retry any failed load requests that would result in a |
final @NonNull ItemSnapshotList<@NonNull T> |
snapshot() Returns a new |
@NonNull
public final @NonNull CombinedLoadStates loadState
A CombinedLoadStates
object which represents the current loading state.
@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. |
@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 |
@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 |
@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:
@NonNull
public final ItemSnapshotList<@NonNull T> snapshot()
Returns a new ItemSnapshotList
representing the currently presented items, including any placeholders if they are enabled.