Problem With Implementing Pagination Data Load Before Reach At Last Card
I am trying to implement Pagination in My project but i don't how it loads all the data from Firestore. I tried my Own method to Paginate but i don't where i am wrong with paginati
Solution 1:
My example hope it help
page = 0var previous = 0val viewth = 20
recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() {
overridefunonScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
super.onScrolled(recyclerView, dx, dy)
visible = gridLayoutManager.childCount
total = gridLayoutManager.itemCount
past = gridLayoutManager.findFirstVisibleItemPosition()
if (dy > 0) {
if (loading) {
if (total > previous) {
loading = false
previous = total
}
}
if (!loading && (total - visible) <= (past + viewth)) {
page++
getNextData(page.toString(), range)//call your next set
loading = true
}
} else {
mSwipeRefreshLayout.isEnabled = gridLayoutManager.findFirstCompletelyVisibleItemPosition() == 0
}
}
overridefunonScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
super.onScrollStateChanged(recyclerView, newState)
mSwipeRefreshLayout.isEnabled = gridLayoutManager.findFirstCompletelyVisibleItemPosition() == 0
}
})
Solution 2:
try to edit Git More Book
like this
privatefungetMoreBooks(lastBook: Timestamp) {
bookCollection
.orderByChild("created_at", Query.Direction.DESCENDING)
.equalTo(lastBook)
.limitToFirst(10).get()
.addOnSuccessListener {booksSnapshot ->
if (!booksSnapshot.isEmpty) {
for (bookSnapShot in booksSnapshot.documents) {
val hashmap = bookSnapShot.data
hashmap?.put("id", bookSnapShot.id)
val bookData = Gson().toJson(hashmap)
val book = Gson().fromJson<Book>(bookData, Book::class.java)
adapter.addDatainList(book)
}
}
}
}
Post a Comment for "Problem With Implementing Pagination Data Load Before Reach At Last Card"