I have list of posts in firebase realtime databse. And each item has unique id. Example is shown in below image.
For retrieving data from firebase i used this query.
FirebaseDatabase.getInstance().getReference().child("Posts").limitToLast(4)
.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot snapshot : dataSnapshot.getChildren())
{
Post post= snapshot.getValue(Post.class);
PostList.add(post);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
I used limitToLast(4)
.
Means i will get the last 4 item and PostList
fill like.
First Element(last fourth node value)
second Element(last third node value)
third Element (last second node value)
fourth Element (last node value)
So, Now the problem is that i want reorder in PostList
.
First Element(last node value)
second Element(last second node value)
third Element (last third node value)
fourth Element (last fourth node value).