27

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")
  }
}
Kotlin Learner
  • 3,995
  • 6
  • 47
  • 127
Frank Mung No
  • 490
  • 1
  • 4
  • 9

1 Answers1

63

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

LazyColumn() {
    itemsIndexed(viewModel.list) { index, item ->
        //..
    }
}
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841