Created
May 1, 2022 06:26
-
-
Save harry-private/d00bde12804a17ce7e0932642e673e62 to your computer and use it in GitHub Desktop.
when you select an item, and you need to put that item in a list, and keep want to keep the state of checkbox
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun SomeScreen(){ | |
val selectedItems:List<Type> = remeber {mutableStateOf(listOf())} | |
val someList:List<SomeType> = stateFromViewModel | |
LazyColumn(){ | |
Items(selectItems.size){ | |
selectItems.value[it].someProperty | |
} | |
Items(someList.size){ | |
Row{ | |
Checkbox( | |
checked = selectedItems.value.contains(searchHistory), | |
onCheckedChange = { | |
// isWordChecked = it | |
if (it) { | |
selectedItems.value = selectedItems.value.plus(searchHistory) | |
} else { | |
selectedItems.value = selectedItems.value.minus(searchHistory) | |
} | |
}, | |
modifier = Modifier | |
.size(20.dp) | |
) | |
Text(someList[it].someProperty) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment