41

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")
  }
}
1
  • 2
    Use itemsIndexed(itemsList) { index, item -> instead of items Commented Jan 18, 2022 at 13:00

1 Answer 1

104

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

LazyColumn() {
    itemsIndexed(viewModel.list) { index, item ->
        //..
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.