https://kotlinlang.org logo
#compose
Title
# compose
l

loloof64

12/15/2021, 10:53 AM
Hi ! Is it possible to know which item of a LazyColumn has been clicked ? More in 🧵
This is how I plan to use LazyColumn
Copy code
LazyColumn(
        modifier = Modifier.background(Color.White).clickable { 
 // ??? How to know which item is cliked ??? ///
},
        contentPadding = PaddingValues(10.dp),
        verticalArrangement = Arrangement.spacedBy(7.dp)
    ) {
arrayOf(
            AssetFileData(caption = "Test sample", assetPath = "pgn/dummy_sample.pgn"),
            AssetFileData(caption = "Capablanca's model", assetPath = "pgn/capablanca.pgn"),
        ).map {
            item {
                FileItem(fileData = it)
            }
        }
}
e

eygraber

12/15/2021, 10:55 AM
Haven't worked with it much, so this is a total guess, but you should probably add the clickable on the item. Then you'd have a reference to which item was clicked.
l

loloof64

12/15/2021, 10:56 AM
Thank you, but it seems that the item does not accept a click handler. Will have a double check.
e

eygraber

12/15/2021, 10:56 AM
You can wrap it in a box
👍🏾 1
l

loloof64

12/15/2021, 10:57 AM
Ok thank you. I'll try now
Ok it seems to be the way to go. Thank you. 🙂
a

Adam Powell

12/15/2021, 2:26 PM
Your FileItem composable should probably accept a Modifier parameter, that would let you skip an extra wrapper Box or similar
👍🏾 1
c

Colton Idle

12/15/2021, 2:55 PM
yep. like Adam said. This was really enlightening for me: https://chris.banes.dev/always-provide-a-modifier/
👍🏾 1
l

loloof64

12/16/2021, 11:18 AM
Thank you @Adam Powell and @Colton Idle, so I'll modify the
FileItem
this way, with an extra
Modifier
parameter.
2 Views