Home » Questions » Computers [ Ask a new question ]

java - How to do handle pagination with Extension method? -

java - How to do handle pagination with Extension method? -

"I have next Extension method for pagination which work with News Api
fun pagination(viewModel: EverythingViewModel): RecyclerView.OnScrollListener {
return object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
super.onScrolled(recyclerView, dx, dy)

if (dy > 0) {
val layoutManager = recyclerView.layoutManager as LinearLayoutManager
val firstVisibleItemPosition = layoutManager.findFirstVisibleItemPosition()
val visibleItemCount = layoutManager.childCount
val totalItemCount = layoutManager.itemCount
if (visibleItemCount + firstVisibleItemPosition >= totalItemCount) {
viewModel.page++
viewModel.getEverything()
}
}
}
}
}

And this method is called like this
everythingRecycler.addOnScrollListener(pagination(viewModel))

But this code works crookedly and also I have three fragment and how I need to change this Extension method that I can use this method for three fragment and with different viewModel





java android kotlin android-recyclerview pagination












ShareShare a link to this question Copy linkCC BY-SA 4.0




Follow
Follow this question to receive notifications











asked 3 mins ago





Tapchylov RadinTapchylov Radin

111 bronze badge





New contributor



Tapchylov Radin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct."

Asked by: Guest | Views: 393
Total answers/comments: 0