6

I'm looking for a way to implement infinite scrolling in my Firebase app.

I'm retrieving my data the following way :

I have a list of keys (items a user created, items a user liked and stuff like this) that I am sending to an adapter which gets the data like this :

 public void onBindViewHolder(final BaseViewHolder viewHolder, final int position) {

    DatabaseReference ref = getAllItemsRef().child(itemIDs.get(position));

    ValueEventListener itemListener = new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            Item item = dataSnapshot.getValue(Item.class);
            viewHolder.bindItem(item);
        }

        @Override
        public void onCancelled(DatabaseError firebaseError) {
        }
    };
    ref.addValueEventListener(itemListener);

}

I would like to add infinite scrolling to gain performance but I have no idea how I should do that with Firebase.

I've seen that FirebaseUI would like to implement it but haven't done it yet.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
schwdim
  • 193
  • 1
  • 2
  • 15
  • Possible duplicate of [Infinite scroll with AngularJs and Firebase](http://stackoverflow.com/questions/22868604/infinite-scroll-with-angularjs-and-firebase) – Chad Robinson Feb 15 '17 at 20:11

1 Answers1

1

It is very simply achievable with a combination of startAt, limitToLast and orderByKey/orderByChild

Seb
  • 500
  • 5
  • 13