{% setvar book_path %}/reference/kotlin/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}
class LazyPagingItems<T : Any>
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 : Any> |
the type of value used by |
Public properties |
|
---|---|
Int |
The number of items which can be accessed. |
CombinedLoadStates |
A |
Public functions |
|
---|---|
operator T? |
Returns the item specified at |
T? |
Returns the presented item at the specified position, without notifying Paging of the item access that would normally trigger page loads. |
Unit |
refresh() Refresh the data presented by this |
Unit |
retry() Retry any failed load requests that would result in a |
ItemSnapshotList<T> |
snapshot() Returns a new |
val loadState: CombinedLoadStates
A CombinedLoadStates
object which represents the current loading state.
operator fun get(index: Int): T?
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 | |
---|---|
index: Int |
the index of the item which should be returned. |
fun peek(index: Int): T?
Returns the presented item at the specified position, without notifying Paging of the item access that would normally trigger page loads.
Parameters | |
---|---|
index: Int |
Index of the presented item to return, including placeholders. |
Returns | |
---|---|
T? |
The presented item at position |
fun refresh(): Unit
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 |
fun retry(): Unit
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:
fun snapshot(): ItemSnapshotList<T>
Returns a new ItemSnapshotList
representing the currently presented items, including any placeholders if they are enabled.