Reputation: 489
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)
)
Upvotes: 9
Views: 6086
Reputation: 365028
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.
Upvotes: 21