Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • Pagination in android recyclerview

    • 0
    • 0
    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 12.1k
    Comment on it

     Step 1- Defined here  some necessary variable  

       boolean isLoading=false;    -> this variable will use to show progressbar below to recyclerview in your xml file  when you scroll your recyclerview list .
      int mPageSize=10;  -> Number of items you want to fetch from server in a once.

    Step-2 Set addOnScrollListener to recyclerview

    int mTotalItemsCount -> Total item on server side.
    recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
                public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                    super.onScrollStateChanged(recyclerView, newState);
                public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                    super.onScrolled(recyclerView, dx, dy);
                    // if dy>0 scrolling down side
                    // if dy<0 scrolling upper side
                    if (dy < 0) {
                        if ((!isLoading && linearLayoutManager.findFirstCompletelyVisibleItemPosition() == 1) && itemsList.size() < mTotalItemsCount) {
                            isLoading = true;
    // this method return pageIndex every time when you hit server to get new data.
                            mPageIndex = returnPageIndex(itemsList.size());

    Step-3 Call loadMoreItems method

    private void loadMoreItems(int mPageIndex) {
            if (AppUtility.isInternetAvailable(this) == false) {
                AppUtility.showAlertDialog(this, getString(R.string.app_name), getString(R.string.connection_error));
            // Here will go your server side request code
                    // after get response from server gone visibility to progressbar
                // add response items to you items list
                 // notify adapter
                // set isLoading to false
                 isLoading = false;

    Step-4 Call returnPageIndex method

    private int returnPageIndex(int sizeOfList) {
            int index = sizeOfList / mPageSize;
            return index;


 1 Comment(s)

  • Hi Arvind, i have a rest api in which there are 10 pages and in each page there are 10 videos , i want to do pagination so that when user scrolls then next 10 videos should be fetched from api and page no should change to 0 to 1 and again when user scrolls then page should change from 1 to 2 and so on and next 10 videos should be fetched . PLease help me to do same. I am using retrofit and in my base url i have put pageno as a counter , i am not able to understand where should i increment that counter. Please help me.
Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: