Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How create Recycler View Grid pagination?

I created Recycler View Grid. And I want realize pagination. But I do not understand how do it. I Found one answer enter link description here

But it not work for me. I have not method mLayoutManager.findFirstVisibleItemPosition(); in my LayOutManager. And method mRecyclerView.setOnScrollListener is deprecated. How can I realize pagination in Recycler View Grid?

like image 876
ip696 Avatar asked Jun 25 '15 08:06

ip696


People also ask

What is LayoutManager in RecyclerView?

A LayoutManager is responsible for measuring and positioning item views within a RecyclerView as well as determining the policy for when to recycle item views that are no longer visible to the user.


1 Answers

Late answer but you can try this..and It works perfectly

allMovie_recycler_view.addOnScrollListener(object : RecyclerView.OnScrollListener() {
        override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
            super.onScrolled(recyclerView, dx, dy)
            if (dy > 0) {

                val layoutManager = allMovie_recycler_view.layoutManager as GridLayoutManager
                val visibleItemCount = layoutManager.findLastCompletelyVisibleItemPosition()+1
                if (visibleItemCount == layoutManager.itemCount){
                    //Load more data
                }


            }
        }
    })
like image 139
Musfick Jamil Avatar answered Sep 25 '22 16:09

Musfick Jamil