Firebase在哪里使用" orderByChild"方法

时间:2017-03-15 11:36:48

标签: android firebase firebase-realtime-database

我正在使用Firebase,我需要按用户名对数据进行排序,但我在下面使用这些方法的问题,我无法理解我在哪里可以使用" orderByChild"方法:

这是我的json(我手动编辑隐藏了一些秘密数据):

"Following" : {
    "ORBBKfZAAUhqI1h7ojQDzYOjgkp1" : { 
       "pypD1SYZkbcYesk09WuMUY1AkTf1": true,
      //Now I am showing the posts for following users only
      //And I need to sort posts by Username so where can 
      //I user orderByChild method to sort from "A" to "Z"
  },
  "Posts" : {
    "-KduqnVVczZf5uibQiZ-" : {
      "Describe" : "hello1",
      "Time" : 14881230655,
      "UID" : "pypD1SYZkbcYesk09WuMUY1AkTf1",
      "Username" : "Dom"
    },
    "-Ke5gJ00CxbjhOuhzLIx" : {
      "Describe" : "hello2",
      "Time" : 1488318465,
      "UID" : "pypD1SYZkbcYesk09WuMUY1AkTf1",
      "Username" : "Jice"
    },
    "-KeCuiFmUCpN19zwsTsR" : {
      "Describe" : "hello3",
      "Time" : 1488439652,
      "UID" : "z2SNUlLd6mQM8nnlkU2VUws5Ggl2",
      "Username" : "Ali"
    },
}

这是我的班级方法:

mDatabaseFriends.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            for(final DataSnapshot following : dataSnapshot.getChildren()) {
                Query ZZ = mDatabase.orderByChild("UID").equalTo(following.getKey());
                ZZ.addChildEventListener(new ChildEventListener() {
                    @Override
                    public void onChildAdded(DataSnapshot dataSnapshot, String s) {

                        mAdapter.add(mAdapter.mdataSet.size(),dataSnapshot.getValue(Getting_Posts.class));}

等兄弟们帮忙。

0 个答案:

没有答案