I have an array of 18 elements that I create a dro...
# compose
j
I have an array of 18 elements that I create a dropdown menu with, so I have an array of states so when I move one over I expect it to stay moved. The problem is that it isn't. The array of remembered states has the correct values, which is what confuses me. This is my source:
Copy code
enum class ClothingTypes(val clothingLabel:String) {
    BLAZER("blazer"),
    BLOUSE("blouse"),
    BODY("body");

    companion object {
        fun getNumberOfItems() = values().size
    }
}
And this is my code, but I am not certain why it doesn't remember the state for each one. You can see the code under androidApp in https://github.com/jblack975/MyOutfitPicker/tree/initial_ui
Copy code
var selectedIndex by remember { mutableStateOf(MutableList(ClothingTypes.getNumberOfItems()) { 0 }) }
val checkedState = remember { mutableStateOf(MutableList(ClothingTypes.getNumberOfItems()) { false }) }
Column {
    DropdownMenu(
        expanded = expanded,
        onDismissRequest = { expanded = false },
        modifier = Modifier.background(Color.LightGray)
    ) {
        ClothingTypes.values().forEachIndexed { index, s ->
            DropdownMenuItem(onClick = {
                selectedIndex[index] = index
                expanded = true
            }) {
                Switch(
                    checked = checkedState.value[index],
                    onCheckedChange = { checkedState.value[index] = it }
                )
                Text(text = s.clothingLabel)
            }
        }
    }
    Text(text = "outfit view", style = MaterialTheme.typography.h6)
}
j
@Albert Chang, thank you for the link and for not making me feel stupid. Very considerate and I am still reading through but now at least I understand why it wasn't working.
👍 1