Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to add a SwipeRefreshLayout in the XML layout.
Android Kotlin
<androidx.swiperefreshlayout.widget.[1] android:layout_width="match_parent" android:layout_height="match_parent"> <!-- Your content here --> </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using RecyclerView or ScrollView as the root instead of SwipeRefreshLayout.
Misspelling the class name.
✗ Incorrect
The root layout for pull-to-refresh is SwipeRefreshLayout.
2fill in blank
mediumComplete the Kotlin code to set the refresh listener on SwipeRefreshLayout.
Android Kotlin
swipeRefreshLayout.[1] {
// Refresh data here
swipeRefreshLayout.isRefreshing = false
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using click or touch listeners instead of refresh listener.
Confusing scroll change with refresh.
✗ Incorrect
The method to listen for pull-to-refresh is setOnRefreshListener.
3fill in blank
hardFix the error in setting the refreshing state after data load.
Android Kotlin
swipeRefreshLayout.isRefreshing = [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting isRefreshing to true after refresh.
Using string "false" instead of boolean false.
✗ Incorrect
After refresh completes, set isRefreshing to false to hide the spinner.
4fill in blank
hardFill both blanks to create a SwipeRefreshLayout and set its color scheme.
Android Kotlin
val swipeRefreshLayout = findViewById<[1]>(R.id.swipeRefreshLayout) swipeRefreshLayout.setColorSchemeColors([2])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using RecyclerView instead of SwipeRefreshLayout.
Passing a view ID instead of a color resource.
✗ Incorrect
Use SwipeRefreshLayout for the view and set a color from android.R.color for the spinner.
5fill in blank
hardFill all three blanks to implement pull-to-refresh that updates a TextView.
Android Kotlin
swipeRefreshLayout.setOnRefreshListener {
textView.text = [1]
swipeRefreshLayout.isRefreshing = [2]
Toast.makeText(this, [3], Toast.LENGTH_SHORT).show()
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting isRefreshing to true inside the listener.
Using incorrect string messages or missing quotes.
✗ Incorrect
Set the TextView text to "Refreshed!", stop refreshing with false, and show a toast "Data updated".