Home > Net >  How to load 'n' (latest) items in Recycler view every time scrolling down .So it doesn
How to load 'n' (latest) items in Recycler view every time scrolling down .So it doesn

Time:09-06

Hey there I only want to load the first 2 items from the Firebase Realtime database to my recycler view but the problem is it returns only 2 images and I want to load the first 2 images out of 'n' no. of image (for ex. return the first 2 images out of 'n' then scrolling down return 2 new images (like that in Instagram) and not download all images offscreen and show it on scrolling). Here is the code but I get only 2 fixed items. Help!

    public int getItemCount() {
            int size = mClicks.size();
            
          return (size > 2 ? 2 : size);
    }

CodePudding user response:

How to load the first n items in RecyclerView every time scrolling down?

What you're looking for is called pagination. This means that you need to load the data progressively in smaller chunks. This was already covered a lot of times before, and this question already has a lot of solutions for the Realtime Database:

However, if you consider at some point in time trying using Cloud Firestore, I think that this answer will help:

If you want to go further and try using Jetpack Compose, then I think that this resource will help:

How to implement pagination in Firestore using Jetpack Compose?

CodePudding user response:

You should use Integer.MAX_VALUE. Something like this.

 public int getItemCount() {            
      return Integer.MAX_VALUE;
}

or simply use

public int getItemCount() {            
      return itemList.size();
}
  • Related