简体   繁体   English

访问Firebase中快照的所有子值

[英]Access all child values of a snapshot in firebase

This is my Firebase Realtime Database. 这是我的Firebase实时数据库。 I want to read memberRollNo , and memberMobileNo of the node whose name(key) is equal to nname. 我想读取name(key)等于nname的节点的memberRollNo和memberMobileNo。 I am only able to read memberRollNo with my code and Textview for memberMobileNo shows out to be blank. 我只能用我的代码读取memberRollNo,而memberMobileNo的Textview显示为空白。

 DBRef = FirebaseDatabase.getInstance().getReference();

    DBRef.child("Members").addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {


                String roll = dataSnapshot.child(nname).child("memberRollNo").getValue(String.class);
                DRollNo.setText(roll);


                String mob = dataSnapshot.child(nname).child("memberMobile").getValue(String.class);
                DMobile.setText(mob);


        }


        @Override
        public void onCancelled(@NonNull DatabaseError databaseError) {

        }
    });
}

DRollNo and DMobile are textview. DRollNo和DMobile是textview。

Change this: 更改此:

String mob = dataSnapshot.child(nname).child("memberMobile").getValue(String.class);

into this: 到这个:

 String mob = dataSnapshot.child(nname).child("memberPhone").getValue(String.class);

In your database, you do not have a child called memberMobile . 在数据库中,没有一个名为memberMobile的子memberMobile The name inside the method child() needs to be the same as in the database to be able to retrieve it. 方法child()的名称必须与数据库中的名称相同才能检索它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM