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()
})
}
}
}
}
I try to make Toast in a normal way. but I got the error I tried a lot of multiples source but failed.
Create an extension function, and call this extension function with your context like context. getActivity(). Show activity on this post. Show activity on this post.
Creating your first Jetpack Compose project is surprisingly easy. Just download the latest Canary version of Android studio and select a new Compose project from the list of possible Android projects. To start you'll have a simple “Hello world!” Text composable.
Update March 2021: The previous answer has been deprecated. You should now use:
val context = LocalContext.current
You can access to context with define ambientContext
.
Example:
val context = ContextAmbient.current
ContextAmbient
and AmbientContext
has been deprecated.
You can replace them with LocalContext
Example:
val context = LocalContext.current
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With