I have a LazyColumn of Text(). I've set clickable for Text() but it's equivalent to OnClickListner. Now I want to set an equivalent of setOnLongClickListener. How can I do that?
@Composable
fun MyText(name: String, modifier: Modifier = Modifier) {
var isSelected by remember {
mutableStateOf(false)
}
Text(
text = "Hello $name!",
modifier = modifier
.clickable { isSelected = !isSelected }
.padding(16.dp)
)
You can use the combinedClickable modifier to get the different click events:
Text(
text = text,
modifier = Modifier
.combinedClickable(
onLongClick = { /*....*/ },
onClick ={ /*....*/ })
.padding(16.dp)
)
Notice that it is an @ExperimentalFoundationApi feature and is likely to change or be removed in the future.
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