Frank Mung No
Frank Mung No

Reputation: 590

Android Jetpack Compose Lazy column items with index?

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")
  }
}

Upvotes: 37

Views: 30705

Answers (1)

Gabriele Mariotti
Gabriele Mariotti

Reputation: 364401

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

LazyColumn() {
    itemsIndexed(viewModel.list) { index, item ->
        //..
    }
}

Upvotes: 98

Related Questions