Reputation: 246
Please help me i need to add pagination in android firestore i have used base adapter to get events from firebase. i have read doc didn't find solution.
DocumentSnapshot lastVisible = documentSnapshots.getDocuments()
.get(documentSnapshots.size() -1);
// Construct a new query starting at this document,
// get the next 25 cities.
Query next = db.collection("cities")
.orderBy("population")
.startAfter(lastVisible)
.limit(25);
// Use the query for pagination
// ...
what i want is that i want to fetch next data and add it in my same list also i want to add event listeners in them and add data at the bottom of the list. How to call the next query for the same listener so that i could change data at runtime. Thanks in advance.
Upvotes: 0
Views: 1304
Reputation: 139039
This is the easiest way in which you can paginate a query using a ListView
and an ArrayAdapter
on button click. A more complex approach would be found in this example where I have explained how you can paginate a query when user scrolls using a RecyclerView
and a custom adapter.
In both examples, the key for solving the problem is to use the startAfter()
method. So you can paginate queries by combining query cursors with the limit() method. You need to use the last document in a batch as the start of a cursor for the next batch.
If you'll prefer to use the second approach, I also recommend you take a look at this video for a better understanding.
If you want a solution for a real-time pagination, please check the following article:
Upvotes: 1