Endless Scrolling in Recycleview.

suggest change

Here I have shared a code snippet for implementing endless scrolling in recycle view.

Step 1: Declare an abstract method on the RecyclerView adapter:

public abstract class ViewAllCategoryAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    public abstract void load();
}

Step 2: Override onBindViewHolder and getItemCount(), and call load() from the last row:

@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
    if ((position >= getItemCount() - 1)) {
        load();
    }
}

@Override
public int getItemCount() {
    return YOURLIST.size();
}

onBindViewHolder runs again whenever that row is rebound, so load() can start another fetch for the same end of the list.

Step 3: Override load() where you construct the adapter. The method runs when the user reaches the end of the list.

adapter = new ViewAllCategoryAdapter(CONTEXT, YOURLIST) {
      @Override
      public void load() {

          /* do your stuff here */
          /* Called when the user reaches the end of the list. */
      }
  };
  recycleCategory.setAdapter(adapter);

load() then runs as the user scrolls to the end of the list.

Best Luck

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents