Skip to content

Instantly share code, notes, and snippets.

@harry-private
Created May 1, 2022 06:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harry-private/d00bde12804a17ce7e0932642e673e62 to your computer and use it in GitHub Desktop.
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
@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