I have a feed filled by comments and I simply it to load the newest ones first and when the user request more comments they will get loaded (from the newest to the oldest one).
This is how my db looks like:
So let's suppose I want to return only 1 comment at a time for starting... The feed would start with the last comment in the db list cause it's the more recent one and then when the user request it I want to load the middle one but it has to be placed below on my recyclerView and so on...
Here's my code:
private void loadData(long lastDate) {
Query query;
if (lastDate == 0) {
query = Util.mServerDatabaseRef.child(Util.getServer().getServerUID()).child("timeline").child("commentList").orderByChild("date").limitToLast(1);
} else {
query = Util.mServerDatabaseRef.child(Util.getServer().getServerUID()).child("timeline").child("commentList").orderByChild("date").endAt(lastDate).limitToFirst(1);
}
new Thread(() -> query.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
commentList = new ArrayList<>();
for (DataSnapshot userSnapshot : dataSnapshot.getChildren()) {
commentList.add(userSnapshot.getValue(Comment.class));
adapter.notifyDataSetChanged();
}
mIsLoading = false;
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
mIsLoading = false;
}
})).start();
}
lastDate is the date of the last comment is my adapter list;
The first loading works just fine, but I can't fix this to retrieve the comments from newest to oldest and place it below each time. The way it is it will return or the same comment or the oldest one and will place it on the top of the list. Of course I need it to work for more than 1 comment at a time too. Any help is appreciated

I will try to give you the idea, the below is not tested. But it should give you the last comment on first load and then every time you load more it should give you one by one the next comments:
Try to keep a reference of the time of the comment before your last comment:
The first time you load, load the last comment and keep reference for the time before it:
Now every time you want to load more try to end at the reference of the date before last: