I'm trying to show post contents sorted by time in an endless recyclerview.
So first I initialized the recyclerview
FirebaseDatabase.getInstance().getReference().child("topics").child("all")
.limitToLast(10)
.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot d : dataSnapshot.getChildren()){
topics.add(d);
if (dataSnapshot.getChildrenCount()==topics.size()){
currentID = topics.get(0).getKey();
Collections.reverse(topics);
adapter.updateList(topics);
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
Then on scroll end I called again
private void loadMoreData(){
loading.setVisibility(View.VISIBLE);
EACH_LOAD_DATA_NUMBER = EACH_LOAD_DATA_NUMBER + 10;
FirebaseDatabase.getInstance().getReference().child("topics").child("all")
.orderByChild("time")
.limitToLast(EACH_LOAD_DATA_NUMBER)
.endAt(currentID)
.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot d : dataSnapshot.getChildren()){
topics.add(d);
if (dataSnapshot.getChildrenCount()==topics.size()){
currentID = topics.get(0).getKey();
Collections.reverse(topics);
adapter.updateList(topics);
Log.i("Current ID",topics.get(0).getKey());
loading.setVisibility(View.GONE);
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
On First initialization stage it shows posts sorted by time and in reverse order on recyclerview.
And when I load more. It works fine for next 10 data. But then it repeats old data.
So where can be the problem :(
Thank you..