Challenge - 5 Problems
Pull-to-refresh Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
What happens when user performs pull-to-refresh in this code?
Given this Kotlin Android code snippet using SwipeRefreshLayout, what is the visible behavior when the user pulls down to refresh?
Android Kotlin
val swipeRefreshLayout = findViewById<SwipeRefreshLayout>(R.id.swipeRefreshLayout)
swipeRefreshLayout.setOnRefreshListener {
// Simulate refresh work
Handler(Looper.getMainLooper()).postDelayed({
swipeRefreshLayout.isRefreshing = false
}, 2000)
}Attempts:
2 left
💡 Hint
Think about what isRefreshing controls in SwipeRefreshLayout.
✗ Incorrect
The SwipeRefreshLayout shows a spinning indicator when isRefreshing is true. The code sets it to false after 2 seconds, so the indicator appears briefly.
❓ lifecycle
intermediate1:30remaining
When should you stop the refresh indicator in pull-to-refresh?
In Android pull-to-refresh, when is the correct time to set isRefreshing = false?
Attempts:
2 left
💡 Hint
Think about user feedback and when loading ends.
✗ Incorrect
The refresh indicator should stop only after the refresh or data loading finishes, so the user knows the task is done.
📝 Syntax
advanced2:00remaining
Which code snippet correctly sets up pull-to-refresh listener?
Choose the Kotlin code that correctly sets a listener on SwipeRefreshLayout to handle pull-to-refresh.
Attempts:
2 left
💡 Hint
Remember how to pass a lambda as a listener in Kotlin.
✗ Incorrect
Option A correctly passes a lambda to setOnRefreshListener. Option A calls refreshData immediately, C tries to assign a lambda to a method, and D passes a function reference incorrectly.
🔧 Debug
advanced2:30remaining
Why does the refresh indicator never disappear?
Given this code, why does the pull-to-refresh spinner keep spinning forever?
val swipeRefreshLayout = findViewById(R.id.swipeRefreshLayout)
swipeRefreshLayout.setOnRefreshListener {
loadData()
}
fun loadData() {
// fetch data asynchronously
}
Attempts:
2 left
💡 Hint
Check what controls the spinner visibility.
✗ Incorrect
The spinner stays visible until isRefreshing is set to false. The code never sets it false after loadData finishes.
🧠 Conceptual
expert1:30remaining
What is the main benefit of using pull-to-refresh in mobile apps?
Why do mobile apps use pull-to-refresh gestures instead of just buttons to refresh content?
Attempts:
2 left
💡 Hint
Think about user experience and mobile device interaction.
✗ Incorrect
Pull-to-refresh uses a simple swipe gesture that feels natural on touch screens, improving user experience.