I want to sort data by timestamp but I can't. I user this code:
reference = database.getReference("posts");
Query re = reference.orderByChild("timestamp").limitToFirst(20);
//Query re = search.orderByChild("timestamp");
re.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
for (DataSnapshot ds : snapshot.getChildren()){
for (DataSnapshot dataSnapshot : ds.getChildren()){
System.out.println(dataSnapshot);
DataReturn dataReturn = dataSnapshot.getValue(DataReturn.class);
if( dataReturn.getStatus() != null && dataReturn.getStatus().equals("approved")){
list.add(dataReturn);
}
}
//Collections.reverse(list);
customAdapter.notifyDataSetChanged();
}
if (refresh){
swipeRefreshLayout.setRefreshing(false);
refresh = false;
}
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
error.toException();
}
});
what I can do now?
my database url json
https://hello-writer-2db52-default-rtdb.firebaseio.com/
How can I sort data in this condition.
I don't get any error