i try to get values for my Recyclerview ordered By a timestamp. My Firebase DatabaseStructure looks like the following:
"connections" : {
"matches" : {
"ZYpiuLBRJkcM1cK6tDctKYva7UB3" : {
"ChatId" : "-LG6GS394d_1NotmhnrD",
"lastMsg" : "i wasdsffas asydfhjdadsfoing just fu?an before i met you ok dir?",
"lastMsgBy" : "6dB5rWfSIwez3gO0N0ClBwFJKu53",
"state" : "active",
"ts" : 4
},
"vhsIe0nBBWQ0D9csBpLwgL4Mf293" : {
"ChatId" : "-LG9_RZNm0DgxlhaMaCv",
"lastMsg" : "jj?hjkjäooasASDfsdafasdf? a!?",
"lastMsgBy" : "6dB5rWfSIwez3gO0N0ClBwFJKu53",
"state" : "active",
"ts" : 5
}
to order it by the child ts i created the following:
private void getMyMatchesQuery(final String userId, final String profileImageUrl, final String name){
final String userid = FirebaseAuth.getInstance().getCurrentUser().getUid();
final DatabaseReference ref = FirebaseDatabase.getInstance().getReference().child("Users").child(userid).child("connections").child("matches").child(userId);
Query qi = ref.orderByChild("ts");
qi.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
System.out.println("123value"+dataSnapshot.child("lastMsg").getValue().toString() + dataSnapshot.child("ts").getValue().toString());
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
unfortunately i receive always the first value of the databse , it seems like the method doesnt take care about the ts value. Maybe someone knows out how to solve it?