1

I am trying to sort projects based on the dateAdded:

The tree looks like this:

projects: {
    "someprojectId": {
       dateAdded: Firebase.TimeStamp
    },

    "someProjectid2":{
      dateAdded: Firebase.Timestamp
   }

}

I am calling it like so in android:

mDatabase.child("projects").orderByChild("dateAdded").addValueEventListener(new ValueEventListener() {

However, it is not sorting it correctly, or at all for that matter of fact?

Lion789
  • 4,402
  • 12
  • 58
  • 96

1 Answers1

5

It would help to see how you actually handle the data in onDataChange. But my guess is that you're failing to loop over the children:

mDatabase
  .child("projects")
  .orderByChild("dateAdded")
  .addValueEventListener(new ValueEventListener() {
    public void onDataChange(DataSnapshot snapshot) {
      for (DataSnapshot child: snapshot.getChildren()) {
        System.out.println(child.getKey());
      }
    }
    ...
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Hey thanks, it works I did not realize it groups them in ascending order had to add limitToLast to show the most recent first. Thanks. – Lion789 Oct 23 '16 at 02:03
  • ok, I was wondering if you knew the answer to this? http://stackoverflow.com/questions/40205388/how-to-grab-multiple-paths-and-sort-them-and-bring-back-the-result-in-firebase Also, since I noticed you work for Firebase not sure if you know the issue I am having here as well with the collapseKey http://stackoverflow.com/questions/39923777/firebase-sending-multiple-push-notifications-instead-of-stacking-or-replacing Appreciate it, a big firebase fan here. – Lion789 Oct 23 '16 at 16:57