android4-6 Exercise 2: Selecting a Row =================================== Imports: the chapter's list plus the four state imports. import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue data class Contact(val id: Int, val name: String) @Composable fun ContactRow(contact: Contact, selected: Boolean, onClick: () -> Unit) { Card( modifier = Modifier .fillMaxWidth() .clickable(onClick = onClick) ) { Text( text = if (selected) "${contact.name} (selected)" else contact.name, modifier = Modifier.padding(16.dp) ) } } @Composable fun ContactListScreen(contacts: List) { var selectedId by rememberSaveable { mutableStateOf(null) } LazyColumn( contentPadding = PaddingValues(16.dp), verticalArrangement = Arrangement.spacedBy(8.dp) ) { items(contacts, key = { it.id }) { contact -> ContactRow( contact = contact, selected = contact.id == selectedId, onClick = { selectedId = contact.id } ) } } } "Clear selection": wrap the LazyColumn in a Column and add, above it, Button(onClick = { selectedId = null }) { Text("Clear selection") } The screen (ContactListScreen) owns the selection (selectedId). ContactRow is stateless: it only receives "selected" and "onClick". Expected: tapping a row marks it; the button clears the mark; the mark survives rotation (rememberSaveable). Code unrun.