Tss
Tss

Reputation: 11

Clickable modifier didn't work on Jetpack Compose?

So i'm trying to initiate the navigation on the clickable modifier, but it doesn't work, so what i did is make a Toast function inside the clickable modifier, the toast message doesn't even show up when i click the item, so i figure out the clickable modifier didn't work, here's the part of my code.

@Composable
fun HomeContent(
    orderMovie: List<OrderMovie>,
    modifier: Modifier = Modifier,
    navigateToDetail: (Long) -> Unit,
) {
    val context = LocalContext.current
    Box(modifier = modifier) {
        LazyColumn {
            items(orderMovie, key = { it.movie.id }) { order ->
                MovieListItem(
                    name = order.movie.name,
                    photoUrl = order.movie.photoUrl,
                    desc = order.movie.desc,
                    modifier = Modifier
                        .clickable {
                            navigateToDetail(order.movie.id)
                            Toast.makeText(context, order.movie.id.toString(),Toast.LENGTH_SHORT)
                        }
                )
            }
        }
    }
}

any idea what i did wrong?

For more information : i've tried using the Log function inside the clickable modifier, but even the Log function doesnt return anything on the logcat

Upvotes: 0

Views: 340

Answers (1)

Guillaume Muret
Guillaume Muret

Reputation: 11

Make sure the Modifier parameter is correctly provided to the MovieListItem root item (Box / Row / Column / etc.)

Try to only display something simple (the Toast or a log) in your clickable function to test the click.

Try to display a Text with a clickable function instead of the MovieListItem to be sure that the .clickable function is working.

PS : You missed the .show() after you Toast.makeText().

Upvotes: 0

Related Questions