In my firebase there are comments -
I want to show them in RecyclerView in descending order. So, as you can see I added "-" in date of every comment.
Then I just used -
query.orderByChild("date").limitToFirst(10);
Which is working fine. But I want to paginate so when user click "load more" it should load more ten. To do that I am storing the last comment Id and tried something like this-
query.orderByChild("date").startAt(lastCommentId).limitToFirst(10);
Its not working and not even generating result. I also tried to alter the position of startAt and orderByChild but got no success. Then I tried something like this-
query.orderByKey().startAt(lastCommentId).limitToFirst(10);
Which works fine but I want to arrange them in order of date. so,
query.orderByKey().startAt(lastCommentId).orderByChild("date").limitToFirst(10);
But this crashes my application. I don't understand why it isn't working. I also tried to alter the position of orderByChild but same result.
Can anybody explain me whats the problem and suggest a better solution to what I am trying to do.
Thanks !
Answer
I did some more research on this topic as this is one of the common problem with firebase. I found this video https://www.youtube.com/watch?v=CH9ptm4NeTw
Hope this helps !