2

I am developing an app like tweeter with Firebase, but I am stuck on some point. In newsfeed page, I have to get the user timeline objects. But, getting whole in once and adding all of tem to the listview is not a good approach. I think I have to implement two thing;

  1. Partial load on listview
  2. Partial get data from Firebase.

There are a lot of ways to implement 1. But, I don't know is there any way to get partial data from Firebase (except limittolast) with scrool view. For example; I want to load 10 items to list and when user scrolls Firebase will load the next 10 item otomatically. Is there any way to implement these two together in an efficient way?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
starrystar
  • 668
  • 3
  • 8
  • 22
  • Did you try anything yet? Because this topic has been covered before: http://stackoverflow.com/questions/37711220/firebase-android-pagination and http://stackoverflow.com/questions/37600353/firebase-see-friends-posts/37632534#37632534 – Frank van Puffelen Jun 24 '16 at 22:15

2 Answers2

1

I think you want to implement pagination with endless scrolling.
You will need for that to adapt your data structure to handle it by setting up an index attribute then order by it.

Here is a quick example :

"users": {
        "mehdi": {
            "index" : 0,
            "first_name": "Mehdi",
            "last_name": "Sakout"
        },
        "jhon": {
            "index" : 1,
            "first_name": "Jhon",
            "last_name": "Doe"
        },
        "lahbib": { 
            "index" : 3,
            "first_name": "Lahbib",
            "last_name": "Anik"
        }
}

And your java code

int itemsPerPage = 5;
int currentPage = 0; 
myDatabaseReference.orderByChild("index").startAt(itemsPerPage*currentPage).limitToLast(itemsPerPage)
Mehdi Sakout
  • 773
  • 5
  • 8
1

Actually I found the answer in the following link https://medium.com/@GiacomoRebonato/i-get-your-example-and-i-hoped-that-i-could-do-it-in-i-different-way-6c3a254bb359#.w11amv63z The tutorial says that firstly you get like 101 item and use last item to next query like :

myDatabase.child("timeline").child(user.getUid()).orderByKey().endAt(lastLoadedItemKey).limitToLast(itemNumberToBeLoaded);

I am using the push() keys for timeline objects.

starrystar
  • 668
  • 3
  • 8
  • 22