Firebase to load more items on scroll (Android)

前端 未结 2 1338
[愿得一人]
[愿得一人] 2020-12-30 11:42

I\'m trying to make a chat application, I use Firebase as my backend, I\'m populating my listview onCreate() with the last 10 messages sent, and I just want that when the us

相关标签:
2条回答
  • 2020-12-30 12:23

    you can use startAt(), endAt(), and equalTo() method. When the user reaches the end of the list then call a method to load more from the server. make sure to implements ValueEventListener.

    Query pagination = mDatabase.orderByChild("id").startAt(startAt).endAt(startAt + 10);
    pagination.addListenerForSingleValueEvent(this);
    
    0 讨论(0)
  • 2020-12-30 12:26

    I think you can use endAt()

    ref.orderByChild("creationDate").limitToLast(pageSize).endAt(oldestLocalMessageTime).addValueEventListener
    // pageSize is the number of messages you want to load each time (10)
    // oldestLocalMessageTime is the time of oldest message that you have loaded from Firebase
    // everytime you load/load more messages you need to update oldestLocalMessageTime value
    
    0 讨论(0)
提交回复
热议问题