android tutorial - Endless scrolling in recycleview in android | Developer android - android app development - android studio - android app developement



Here I have shared a code snippet for implementing endless scrolling in recycle view. Step 1: First make a one abstract method in Recycleview adapter like below.

public abstract class ViewAllCategoryAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    public abstract void load();
}
click below button to copy code from our android learning website - android tutorial - team

Step 2: Now override onBindViewHolder and getItemCount() method of ViewAllCategoryAdapter class and call Load() method like below.

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

@Override
public int getItemCount() {
    return YOURLIST.size();
}
click below button to copy code from our android learning website - android tutorial - team

Step 3: Now every backend logic is complete now it's time to execute this logic.It's simple you can override load method where you create object of your adapter.this method is automatically call while user reach at end of the listing.

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

@Override
public int getItemCount() {
    return YOURLIST.size();
}
click below button to copy code from our android learning website - android tutorial - team

Now load() method automatically call while user scroll at end of list. Best Luck


Related Searches toEndless scrolling in recycleview in android