Hey, I'm having some trouble finding a way to cont...
# compose
t
Hey, I'm having some trouble finding a way to control the selection state of an item in a
LazyColumn
. Anyone knows how to do this? What I'm trying to achieve is getting to the selected state on a click (not a long click).
t
You can maintain a selected: Boolean state per item that updates upon
onClick
of a
Button
or
Modifier.clickable
. If you don't allow multi selection, then you also need to keep some state at the level of the whole list itself.
t
@Tash thank you but my question is more about how to make the item adhere to that state. I guess I could always just change the background color manually but that seems wrong.
t
Have you checked out the official Compose sample apps? Something like this, for example, might help figure out your use case: https://github.com/android/compose-samples/blob/26a103c414cc5447385756e04990af596e[…]in/java/com/example/compose/jetsurvey/survey/SurveyQuestions.kt
t
Thank you. I was looking for the
selectable
modifier which I found your link.
Turns out I was actually looking for
combinedClickable
(the variant where you can define the
interactionSource
and
indication
).
👍🏼 1