Complete the code to set the initial page number to 1.
var currentPage = [1]The first page number in pagination usually starts at 1 to represent the first set of data.
Complete the code to increase the page number by 1 when loading the next page.
currentPage [1] 1
To move to the next page, you add 1 to the current page number.
Fix the error in the code to correctly check if the current page is the last page.
if (currentPage [1] totalPages) { // No more pages to load }
To check if the current page is the last page, compare if currentPage equals totalPages.
Fill both blanks to create a function that returns true if there are more pages to load.
fun hasMorePages(currentPage: Int, totalPages: Int): Boolean {
return currentPage [1] totalPages
}The function should return true if the current page is less than total pages, meaning more pages exist.
Fill all three blanks to create a map of page numbers to their data lists, filtering only pages with data.
val pagesData = mapOf(
[1] to listOf("Item1", "Item2"),
[2] to listOf(),
[3] to listOf("Item3")
).filter { it.value.isNotEmpty() }The map keys are page numbers 1, 2, and 3. The filter removes pages with empty lists, so page 2 is excluded.