Reputation: 1616
I constructed a lazycolumn where on every row I set pointer listeners. What I want is that after long click on any row, the following clicks will be in selection mode and change the background color of the row. The long click works as intended, but the clicks afterwards, though receiving the events and setting associated values correctly, don't seem to make the UI refresh (or recompose), and so the background colors are not set. Any ideas please?
var selectedIndex by remember { mutableStateOf(-1) }
LazyColumn {
itemsIndexed(lazyPagingItems) { index, row ->
Row(
modifier = Modifier
.fillMaxWidth()
.pointerInput(Unit) {
detectTapGestures(
onLongPress = {
onLongClickAction(row, index)
selectedIndex++
},
onTap = {
println("clicked $index $selectMode")
if (!selectMode) {
println("$index " + colorSelected(index))
} else {
selectMap[index] = row
}
selectedIndex++
println("$index " + colorSelected(index))
}
)
}
.background(colorResource(colorSelected(index))),
horizontalArrangement = Arrangement.SpaceBetween
) {
Text(
text = index.toString(),
modifier = Modifier.padding(end = 2.dp)
)
}
}
}
Upvotes: 2
Views: 855