Long Press Item Select In Jetpack Compose

Jayant Kumar🇮🇳
3 min readOct 7, 2023
Photo by Ehud Neuhaus on Unsplash

In this article we will see how to select items when we press long click in Jetpack Compose.

As you can see in the above video , when we long press on any of the items, we are abled to select the remaining items also when you click on selectAll checkbox , all the items will be selected. Let’s see how we can make this thing with Jetpack Compose.

@OptIn(ExperimentalFoundationApi::class)
@Composable
fun EachRow(
modifier: Modifier = Modifier,
title: String,
isEnabled: Boolean,
selectedItem: Boolean,
onClick: () -> Unit,
onEnableChange: (Boolean) -> Unit
) {

Box(
modifier = modifier
.padding(15.dp)
.background(Color.LightGray, RoundedCornerShape(4.dp))
.size(80.dp)
.combinedClickable(onLongClick = {
onEnableChange(true)
}, onClick = onClick)
) {
if (isEnabled)
Checkbox(
checked = selectedItem, onCheckedChange = null, modifier = Modifier
.padding(10.dp)
.align(Alignment.TopEnd)
)
Text(
text = title, style = TextStyle(
color = Color.Black, fontSize =…

--

--

Jayant Kumar🇮🇳
Jayant Kumar🇮🇳

Written by Jayant Kumar🇮🇳

Hello My name is Jayant Kumar, I am a software Engineer , specialist in Mobile Development (Android , IOS , Flutter , React Native and Ionic) from India 🇮🇳

No responses yet