I have a list of options and each of them has a checkbox. I want the user to be able to select only one. Chechkbox:
@Composable
fun CheckboxResource(isSelected: Boolean): Painter {
return if (isSelected) {
painterResource(id = R.drawable.check_on)
} else {
painterResource(id = R.drawable.check_off)
}
}
And the Composable:
fun SelectOptionsCheckbox(
isSelectedOption: Boolean,
onSelectOption: (Boolean) -> Unit
) {
val selectedOption = remember {
mutableStateOf(isSelectedOption)
}
Row {
Text()
Icon(
painter = CheckboxResource(isSelected = selectedOption.value),
contentDescription = "Checkbox",
modifier = Modifier
.clickable {
selectedOption.value = selectedOption.value.not()
onSelectOption(selectedOption.value)
},
)}
In this way the checkbox works but I can select all the options