1

this is my code

@Composable
fun MyComponent() {
    val items = listOf("Option 1", "Option 2", "Option 3")
    var selectedIndex by remember { mutableStateOf(0) }
    var expanded by remember { mutableStateOf(false) }

    Column {
        IconButton(onClick = { expanded = !expanded }) {
            Icon(Icons.Default.MoreVert, contentDescription = "Menu")
        }
        DropdownMenu(
            expanded = expanded,
            onDismissRequest = { expanded = false },
            modifier = Modifier.background(Color.White)
        ) {
            items.forEachIndexed { index, item ->
                DropdownMenuItem(
                    onClick = {
                        selectedIndex = index
                        expanded = false
                    }
                ) {
                    Text(text = item)
                }
            }
        }
    }
}

and no matter what I tried to do when I open the dropdown menu once I cannot close it. It pops up again.

I tried moving the values into a class and that also didn't work.

abasirwani
  • 31
  • 5
  • What versions of Android and Composable are you using? Your code is working fine with Android 13 and those dependencies in the build.gradle: `implementation 'androidx.core:core-ktx:1.7.0' implementation 'androidx.activity:activity-compose:1.3.1' implementation "androidx.compose.ui:ui:$compose_ui_version" implementation "androidx.compose.ui:ui-tooling-preview:$compose_ui_version" implementation 'androidx.compose.material:material:1.2.0' ` – Alberto Vélaz May 20 '23 at 15:05

0 Answers0