itemsIndexed

Function

Android
inline fun <T> LazyListScope.itemsIndexed(
    items: List<T>,
    crossinline itemId: ((index: Int, item: T) -> Long) = { _, _ ->
        LazyListScope.UnspecifiedItemId
    },
    crossinline itemContent: @Composable LazyItemScope.(index: Int, item: T) -> Unit
) = items(items.size, { index: Int -> itemId(index, items[index]) }) { itemContent(it, items[it]) }

Adds a list of items where the content of an item is aware of its index.

Parameters

itemsthe data list
itemIda factory of stable and unique ids representing the item. The value may not be less than or equal to -2^62, as these values are reserved by the Glance API. Specifying the list item ids will maintain the scroll position through app widget updates in Android S and higher devices.
itemContentthe content displayed by a single item
Android
inline fun <T> LazyListScope.itemsIndexed(
    items: Array<T>,
    noinline itemId: ((index: Int, item: T) -> Long) = { _, _ -> LazyListScope.UnspecifiedItemId },
    crossinline itemContent: @Composable LazyItemScope.(index: Int, item: T) -> Unit
) = items(items.size, { index: Int -> itemId(index, items[index]) }) { itemContent(it, items[it]) }

Adds a array of items where the content of an item is aware of its index.

Parameters

itemsthe data array
itemIda factory of stable and unique list item ids. Using the same itemId for multiple items in the array is not allowed. When you specify the itemId the scroll position will be maintained based on the itemId, which means if you add/remove items before the current visible item the item with the given itemId will be kept as the first visible one.
itemContentthe content displayed by a single item
Android
inline fun <T> LazyVerticalGridScope.itemsIndexed(
    items: List<T>,
    crossinline itemId: ((index: Int, item: T) -> Long) = { _, _ ->
        LazyVerticalGridScope.UnspecifiedItemId
    },
    crossinline itemContent: @Composable LazyItemScope.(index: Int, item: T) -> Unit
) = items(items.size, { index: Int -> itemId(index, items[index]) }) { itemContent(it, items[it]) }

Adds a list of items where the content of an item is aware of its index.

Parameters

itemsthe data list
itemIda factory of stable and unique ids representing the item. The value may not be less than or equal to -2^62, as these values are reserved by the Glance API. Specifying the list item ids will maintain the scroll position through app widget updates in Android S and higher devices.
itemContentthe content displayed by a single item
Android
inline fun <T> LazyVerticalGridScope.itemsIndexed(
    items: Array<T>,
    noinline itemId: ((index: Int, item: T) -> Long) = { _, _ ->
        LazyVerticalGridScope.UnspecifiedItemId
    },
    crossinline itemContent: @Composable LazyItemScope.(index: Int, item: T) -> Unit
) = items(items.size, { index: Int -> itemId(index, items[index]) }) { itemContent(it, items[it]) }

Adds a array of items where the content of an item is aware of its index.

Parameters

itemsthe data array
itemIda factory of stable and unique list item ids. Using the same itemId for multiple items in the array is not allowed. When you specify the itemId the scroll position will be maintained based on the itemId, which means if you add/remove items before the current visible item the item with the given itemId will be kept as the first visible one.
itemContentthe content displayed by a single item