How to sort by keywords children in firebase?
I'm trying to sort projects based on dateAdded:
The tree looks like this:
projects: {
"someprojectId": {
dateAdded: Firebase.TimeStamp
},
"someProjectid2":{
dateAdded: Firebase.Timestamp
}
}
I call it like this in android:
mDatabase.child("projects").orderByChild("dateAdded").addValueEventListener(new ValueEventListener() {
However, does it not sort it correctly, or does it not matter at all?
+1
source to share
1 answer
This will help you see how you are actually processing data in onDataChange
. But I guess you cannot iterate over children:
mDatabase
.child("projects")
.orderByChild("dateAdded")
.addValueEventListener(new ValueEventListener() {
public void onDataChange(DataSnapshot snapshot) {
for (DataSnapshot child: snapshot.getChildren()) {
System.out.println(child.getKey());
}
}
...
+4
source to share