Responding to clicks in LazyColumn composables
What if we want to let our users select an item from a presented list? To achieve that, we need to communicate clicks back to our app.
The first step in implementing click interaction is to ensure that our item composable takes a lambda. Internally, the composable then uses the clickable
modifier to identify clicks. When a click is performed, it executes the lambda. Let’s see how this looks for the Employee
composable we discussed earlier, in the Populating a LazyColumn composable section:
@Composable
fun Employee(
employee: EmployeeUiModel, onClick: () -> Unit
) {
Row(modifier = Modifier.clickable {
onClick()
})
{
...
}
}
Next, we can revisit our container of LazyColumn
where Employee
is used:
@Composable
fun Employees...