Get data of all childs of Firebase database

时间:2017-04-06 17:10:27

标签: android firebase firebase-realtime-database

I have a Firebase database with a child as users. This contains two users as user1 and user2. Each of them contain name and address. Now I need to get the value of name and address of user1 and user2.

Thanks in advance.

1 个答案:

答案 0 :(得分:5)

DatabaseReference ref1= FirebaseDatabase.getInstance().getReference();
  DatabaseReference ref2;    
   ref2 = ref1.child("users");


   ref2.addListenerForSingleValueEvent(new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot dataSnapshot) {

        Userlist = new ArrayList<String>();                

        // Result will be holded Here
        for (DataSnapshot dsp : dataSnapshot.getChildren()) {
            Userlist.add(String.valueOf(dsp.geValue())); //add result into array list


        }