I am trying to show a Toast message when I click on the item, but how do I get the context to pass the Toast class?
fun createListItem(itemIndex: Int) {
Padding(left = 8.dp, right = 8.dp, top = 8.dp, bottom = 8.dp) {
FlexRow(crossAxisAlignment = CrossAxisAlignment.Center) {
expanded(1.0f) {
Text("Item $itemIndex")
}
inflexible {
Button(
"Button $itemIndex",
style = ContainedButtonStyle(),
onClick = {
Toast.makeText(
this@MainActivity,
"Item name $itemIndex",
Toast.LENGTH_SHORT
).show()
})
}
}
}
}
ToastinonClickhandlers in Compose without a problem. If you were getting a compile error, please provide the complete details of the error. If you were getting a runtime error, please edit your question and post the stack trace.SnackbaroverToastin Compose: kotlinlang.slack.com/archives/CJLTWPH7S/….