Hi ! Is it possible to know which item of a LazyCo...
# compose
l
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
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
Thank you, but it seems that the item does not accept a click handler. Will have a double check.
e
You can wrap it in a box
👍🏾 1
l
Ok thank you. I'll try now
Ok it seems to be the way to go. Thank you. 🙂
a
Your FileItem composable should probably accept a Modifier parameter, that would let you skip an extra wrapper Box or similar
👍🏾 1
c
yep. like Adam said. This was really enlightening for me: https://chris.banes.dev/always-provide-a-modifier/
👍🏾 1
l
Thank you @Adam Powell and @Colton Idle, so I'll modify the
FileItem
this way, with an extra
Modifier
parameter.