【问题标题】:How to get the list of child nodes from firebase database reference?如何从 firebase 数据库参考中获取子节点列表?
【发布时间】:2018-04-17 12:45:20
【问题描述】:

下面我附上了数据库结构的图片,我正在尝试从 firebase 数据库参考 (timingInformation) 中获取子节点列表。如何获取列表?

【问题讨论】:

    标签: android firebase arraylist firebase-realtime-database


    【解决方案1】:

    要从 Firebase 数据库读取/同步数据,您需要附加一个侦听器。一个简单的案例:

    DatabaseReference ref = FirebaseDatabase.getInstance().getReference("timingInformation");
    ref.addChildEventListener(new ChildEventListener() {
        @Override
        public void onChildAdded(DataSnapshot dataSnapshot, String previousChildName) {
            Log.d(TAG, "onChildAdded:" + dataSnapshot.getKey());
        }
    
        @Override
        public void onChildChanged(DataSnapshot dataSnapshot, String previousChildName) {
            Log.d(TAG, "onChildChanged:" + dataSnapshot.getKey());
        }
    
        @Override
        public void onChildRemoved(DataSnapshot dataSnapshot) {
            Log.d(TAG, "onChildRemoved:" + dataSnapshot.getKey());
        }
    
        @Override
        public void onChildMoved(DataSnapshot dataSnapshot, String previousChildName) {
            Log.d(TAG, "onChildMoved:" + dataSnapshot.getKey());
        }
    
        @Override
        public void onCancelled(DatabaseError databaseError) {
            Log.w(TAG, "onCancelled", databaseError.toException());
        }
    };
    

    如需了解更多信息,请参阅 Firebase documentation on loading data from a listreference documentation on what you can do with a snapshot

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-24
      • 2019-01-03
      • 1970-01-01
      • 2022-07-01
      • 2020-12-22
      • 2022-01-05
      • 2020-06-20
      • 1970-01-01
      相关资源
      最近更新 更多