Skip to content Skip to sidebar Skip to footer

Load Only X Items In Firebase Recycler Adapter

Hi so I have one Firebase FirebaseRecyclerAdapter and in my Firebase project in my database I have over 30 values and in my app I want to display only the first x items. I searched

Solution 1:

To solve this, you should pass to the FirebaseRecyclerAdapter constructor a query instead of the mRef, which I assume is a DatabaseReference object.

Assuming that you have a database structure that looks like this:

Firebase-root
    |
    --- posts
          |
          --- postId
                |
                --- title: "Post Title"
                |
                --- //Other details

To display only the first 5 items, the query should look like this:

DatabaseReferencerootRef= FirebaseDatabase.getInstance().getReference();
Queryquery= rootRef.child("posts").orderByChild("title").limitToFirst(5);
query.addListenerForSingleValueEvent(/* ... */);

Post a Comment for "Load Only X Items In Firebase Recycler Adapter"