Hello, I set a different background color when a l...
# compose
n
Hello, I set a different background color when a list item is clicked. However when its position changes, a different one gets that background color as the previous item’s position had changed. How do I find a more reliable index then?
Copy code
Box(modifier = Modifier.animateItemPlacement()) {
    InstrumentView(instrument = item, selected = selectedIndex == i) {
        selectedIndex = if (selectedIndex != i) i else -1
    }
}
p
If you are using
LazyColumn
, try setting
items()
parameter key. If normal
Column
, soround your composables in
key() {}
composable. Make sure keys are alway unique