简体   繁体   中英

Query in Firebase database child

I'm new to android. Can someone help me to query the below-underlined line in the firebase? The query result should be the underlined String.

在此处输入图像描述

That String is an autogenerated one in the firebase at the Driver signup. So hardcoding that string is not my aim.

Refer to Users/Driver and loop through children, you will get your key:

DatabaseReference mDatabase = FirebaseDatabase.getInstance().getReference().child("Users").child("Driver");


ValueEventListener listener = new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot dataSnapshot) {

      //loop through the children
       for(DataSnapshot ds: dataSnapshot.getChildren()){

         //get the key or keys depending on how many keys

          String underLinedKey = ds.getKey();

       }

    }

    @Override
    public void onCancelled(DatabaseError databaseError) {
        //log error
        Log.w(TAG, "loadPost:onCancelled", databaseError.toException());

    }
};
mDatabase.addValueEventListener(listener);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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