https://kotlinlang.org logo
#compose
Title
# compose
n

Nat Strangerweather

12/04/2020, 6:26 PM
Hi, I have a list of composables that look like this (please see above). I have a Boolean called isDisabled, and I want to assign it to other composables when I select one of them. How can I achieve that? I have now spent two weeks trying everything I can think of, but with no success.
f

Foso

12/04/2020, 8:21 PM
Maybe something like this:
Copy code
@Composable
fun SelectedExample() {
    val selectedIndex = remember { mutableStateOf(0) }

    Column {
        listOf("A", "B", "C").forEachIndexed { index, string ->
            Card(
                Modifier.clickable(onClick = { selectedIndex.value = index }),
                elevation = 8.dp
            ) {
                val isSelected = selectedIndex.value == index
                Text("This is a Card " + string + " isSelected:  " + isSelected)
            }
        }
    }
}
n

Nat Strangerweather

12/04/2020, 8:40 PM
Oh thanks @Foso, I'll give this a try! 😊