title: How to implement pagination in recyclerview?
body: <p>I am performing pagination in recyclerView. My data is loading successfully and problem is how can I request to server for the next page. How i can perform pagination and how i can find page number which is being scrolled.</p>
  
  <p>My code is:</p>
  
  <pre><code>rvLatestProduct.addOnScrollListener(new RecyclerView.OnScrollListener() {
  
          @Override
          public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
              //super.onScrolled(recyclerView, dx, dy);
  
              visibleItemCount = rvLatestProduct.getChildCount();
              totalItemCount = linearLayoutManager.getItemCount();
              firstVisibleItem = linearLayoutManager.findFirstVisibleItemPosition();
              Log.e("totalItemCount",String.valueOf(totalItemCount));
              if (loading) {
                  if (totalItemCount &gt; previousTotal) {
                      loading = false;
                     // currentPage += 1;
                      previousTotal = totalItemCount;
                      Log.e("previousTotal",String.valueOf(previousTotal));
                  }
              }
              if (!loading &amp;&amp; (totalItemCount - visibleItemCount)
                      &lt;= (firstVisibleItem + visibleThreshold)) {
                  //int initialSize = totalItemCount.size;
                  getPagination();
                  //val updatedSize = dataList.size
                //  recyclerView.post { adapter.notifyItemRangeInserted(initialSize, updatedSize) }
                  loading = true;
              }
          }
      });
  </code></pre>
  
  <p>and getPagination(); code is given as</p>
  
  <pre><code>  private void getPagination(){
      final JsonArrayRequest request = new JsonArrayRequest(Request.Method.GET,
              AllURLs.viewAllLatestProduct,null,
              new Response.Listener&lt;JSONArray&gt;() {
                  JSONArray object;
                  @Override
                  public void onResponse(JSONArray response) {
                      try {
                          for (int i=0;i&lt;response.length();i++) {
                            object = response.getJSONArray(i);
                          }
                          setLatestProductAdapter(object);
                          adapter.notifyDataSetChanged();
                         // Toast.makeText(context,"page no" + pageNo,Toast.LENGTH_SHORT).show();
                      } catch (JSONException e) {
                          e.printStackTrace();
                      }
                  }
              }, new Response.ErrorListener() {
          @Override
          public void onErrorResponse(VolleyError error) {
  
          }
      });
      VolleySingleton.getInstance(context).addToRequestQueue(request);
  }
  </code></pre>