Android Jetpack Compose Lazy column items with index?
T

1

36

How to access the current item's index of LazyColumn in Jetpack Compose.

LazyColumn {
  items(viewModel.list) { item ->
      // Here I want to get the index of the item
      Timber.d("item - $item")
  }
}
Tara answered 18/1, 2022 at 12:55 Comment(1)
Use itemsIndexed(itemsList) { index, item -> instead of itemsLithometeor
L
92

You can use the itemsIndexed() extension function which provides the index.

LazyColumn() {
    itemsIndexed(viewModel.list) { index, item ->
        //..
    }
}
Lithometeor answered 18/1, 2022 at 13:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.