Computer scienceMobileJetpack ComposeComposablesMaterial

Checkbox, Radio Button, and Switch

Quiz implementation

Report a typo

Complete the QuizQuestion composable function to achieve this output:

Preview of QuizQuestion

Fill in the gaps with the relevant elements
@Composable
fun QuizQuestion() {
    val options = listOf("Swift", "Kotlin", "Java", "Python")
    val selectedAnswer = remember { mutableStateOf("") }
    
    (modifier = Modifier.padding(16.dp)) {
        ("Which programming language is used for Android development?")
        Spacer(modifier = Modifier.height(16.dp))
        
        options.forEach { option ->
            (verticalAlignment = Alignment.CenterVertically) {
                (
                     = selectedAnswer.value == option,
                     = { selectedAnswer.value = option }
                )
                Text(option, modifier = Modifier.padding(start = 8.dp))
            }
        }
        
        Spacer(modifier = Modifier.height(16.dp))
        Text("Your answer: ${selectedAnswer.value}")
    }
}

Create a free account to access the full topic