Advertisement
Neyasbit

Adapter2

Jul 15th, 2019
519
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.76 KB | None | 0 0
  1. public abstract class RecyclerViewOnScroll extends RecyclerView.OnScrollListener {
  2.  
  3.     @Override
  4.     public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
  5.         super.onScrolled(recyclerView, dx, dy);
  6.  
  7.         if ( dy > 0) {
  8.  
  9.             GridLayoutManager gridLayoutManager = (GridLayoutManager) recyclerView.getLayoutManager();
  10.             int visibleItemCount = gridLayoutManager.getChildCount();
  11.             int totalItemCount = gridLayoutManager.getItemCount();
  12.             int firstVisibleItems = gridLayoutManager.findFirstVisibleItemPosition();
  13.  
  14.             if ((visibleItemCount + firstVisibleItems) >= totalItemCount) {
  15.                 loadMore();
  16.             }
  17.         }
  18.     }
  19.  
  20.     protected abstract void loadMore();
  21.  
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement