0
0
Android Kotlinmobile~10 mins

Pagination basics 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 set the initial page number to 1.

Android Kotlin
var currentPage = [1]
Drag options to blanks, or click blank then click option'
A1
B0
Cnull
D-1
Attempts:
3 left
💡 Hint
Common Mistakes
Starting page number at 0 instead of 1.
Using null or negative numbers for page.
2fill in blank
medium

Complete the code to increase the page number by 1 when loading the next page.

Android Kotlin
currentPage [1] 1
Drag options to blanks, or click blank then click option'
A+=
B/=
C*=
D-=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-=' which decreases the page number.
Using multiplication or division operators.
3fill in blank
hard

Fix the error in the code to correctly check if the current page is the last page.

Android Kotlin
if (currentPage [1] totalPages) {
    // No more pages to load
}
Drag options to blanks, or click blank then click option'
A<
B==
C!=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' or '>' which check for less or greater, not equality.
Using '!=' which checks for inequality.
4fill in blank
hard

Fill both blanks to create a function that returns true if there are more pages to load.

Android Kotlin
fun hasMorePages(currentPage: Int, totalPages: Int): Boolean {
    return currentPage [1] totalPages
}
Drag options to blanks, or click blank then click option'
A>
B==
C<
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' which would be true after last page.
Using '==' which only checks equality.
5fill in blank
hard

Fill all three blanks to create a map of page numbers to their data lists, filtering only pages with data.

Android Kotlin
val pagesData = mapOf(
    [1] to listOf("Item1", "Item2"),
    [2] to listOf(),
    [3] to listOf("Item3")
).filter { it.value.isNotEmpty() }
Drag options to blanks, or click blank then click option'
A1
B2
C3
D4
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-consecutive or invalid page numbers.
Using page numbers not matching the data.