在Listview中检索并显示节点

时间:2017-06-07 17:22:38

标签: android firebase firebase-realtime-database

这里是否有人可以帮助如何在黑匣子中检索那些类部分并在listview中显示它,如果我添加更多类部分,它将自动添加到我的列表视图中。感谢

Click this to see image

1 个答案:

答案 0 :(得分:0)

所以,如果您的数据库结构是这样的..

teacher{
        VRdn7....f1{
                    name:"name"
                    .....
                    class{
                          key1{
               -->             className:"c1"  }
                          key2{
               -->             className:"c2"  }
                          key3{
               -->             className:"c3"  }
                         }
                   }
       }

如果你想要className的值,那么,

    DatabaseReference db = FirebaseDatabase.getInstance()
            .getReference("teacher").child("VRdn7......f1");

    db.child("class").addChildEventListener(new ChildEventListener() {
        @Override
        public void onChildAdded(DataSnapshot dataSnapshot, String s) {


            String className = dataSnapshot.child("className").getValue().toString();
            //This will get all values of className inside "teacher\VRdn7....f1\class\***\"
            // Now create adapter for listview, and then add values in a list....
        }

        @Override
        public void onChildChanged(DataSnapshot dataSnapshot, String s) { }

        @Override
        public void onChildRemoved(DataSnapshot dataSnapshot) { }

        @Override
        public void onChildMoved(DataSnapshot dataSnapshot, String s) { }

        @Override
        public void onCancelled(DatabaseError databaseError) { }
    });