0
0
Android Kotlinmobile~20 mins

Button composable in Android Kotlin - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Button Composable Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2:00remaining
What happens when this Button composable is clicked?
Consider this Kotlin Compose code snippet for a Button. What will be the visible result after clicking the button once?
Android Kotlin
var count by remember { mutableStateOf(0) }
Button(onClick = { count++ }) {
  Text(text = "Clicked: $count")
}
AThe button label updates to show "Clicked: 1" after the first click.
BThe button label stays "Clicked: 0" even after clicking.
CThe app crashes due to missing state initialization.
DThe button disappears after clicking.
Attempts:
2 left
💡 Hint
Remember that mutableStateOf triggers UI recomposition when changed.
📝 Syntax
intermediate
2:00remaining
Which Button composable code snippet is syntactically correct?
Select the option that compiles without errors in Jetpack Compose.
AButton { onClick = { println("Clicked") } Text("Press") }
BButton(onClick = println("Clicked")) { Text("Press") }
CButton(onClick = { println("Clicked") } Text("Press"))
DButton(onClick = { println("Clicked") }) { Text("Press") }
Attempts:
2 left
💡 Hint
The onClick parameter requires a lambda expression.
lifecycle
advanced
2:00remaining
What is the effect of calling setContent inside an Activity multiple times with Button composables?
If an Android Activity calls setContent twice, each time setting a Button composable, what happens to the UI?
AThe app crashes due to multiple setContent calls.
BBoth Buttons appear stacked vertically on the screen.
CThe second setContent replaces the first UI completely, showing only the second Button.
DThe first Button remains visible and the second is ignored.
Attempts:
2 left
💡 Hint
setContent replaces the entire Compose UI content of the Activity.
navigation
advanced
2:00remaining
How to navigate to a new screen on Button click using Jetpack Compose Navigation?
Given a Button inside a composable, which onClick implementation correctly navigates to a "details" screen using NavController?
Android Kotlin
val navController = rememberNavController()
Button(onClick = { /* navigation code here */ }) {
  Text("Go to Details")
}
AonClick = { navController.navigate("details") }
BonClick = { navController.navigateTo("details") }
ConClick = { navController.navigateUp() }
DonClick = { navController.popBackStack("details", false) }
Attempts:
2 left
💡 Hint
Use the navigate() method with the route string to move to a new screen.
🔧 Debug
expert
2:00remaining
Why does this Button not update its label when clicked?
Analyze the code below. Why does the Button label not change after clicking?
Android Kotlin
var count = 0
Button(onClick = { count++ }) {
  Text(text = "Clicked: $count")
}
ABecause the Button's onClick lambda is empty and does not increment count.
BBecause 'count' is not a state variable, Compose does not recompose the UI on change.
CBecause the Text composable does not support string interpolation.
DBecause the Button composable requires a modifier to update its content.
Attempts:
2 left
💡 Hint
Compose only updates UI when state variables change.