0
0
Android Kotlinmobile~10 mins

Pull-to-refresh in Android Kotlin - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
ASwipeRefreshLayout
BRecyclerView
CLinearLayout
DScrollView
Attempts:
3 left
💡 Hint
Common Mistakes
Using RecyclerView or ScrollView as the root instead of SwipeRefreshLayout.
Misspelling the class name.
2fill in blank
medium

Complete 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'
AsetOnScrollChangeListener
BsetOnClickListener
CsetOnTouchListener
DsetOnRefreshListener
Attempts:
3 left
💡 Hint
Common Mistakes
Using click or touch listeners instead of refresh listener.
Confusing scroll change with refresh.
3fill in blank
hard

Fix 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'
Atrue
Bnull
Cfalse
D"false"
Attempts:
3 left
💡 Hint
Common Mistakes
Setting isRefreshing to true after refresh.
Using string "false" instead of boolean false.
4fill in blank
hard

Fill 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'
ASwipeRefreshLayout
BRecyclerView
Candroid.R.color.holo_blue_bright
Dandroid.R.color.holo_red_dark
Attempts:
3 left
💡 Hint
Common Mistakes
Using RecyclerView instead of SwipeRefreshLayout.
Passing a view ID instead of a color resource.
5fill in blank
hard

Fill 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'
A"Refreshed!"
Bfalse
C"Data updated"
Dtrue
Attempts:
3 left
💡 Hint
Common Mistakes
Setting isRefreshing to true inside the listener.
Using incorrect string messages or missing quotes.