Firebase for Android, How can I loop through a child (for each child = x do y)

Rosenberg :

This is what my test looks like:

enter image description here

I won't use the fields above, it's just a dummy. But I would like to go through all the children on "users" and for each email return a:

System.out.println(emailString);

The only way I found of listing an object is using firebaseAdapter, is there another way of doing it?

rubenlop88 :

The easiest way is with a ValueEventListener.

    FirebaseDatabase.getInstance().getReference().child("users")
            .addListenerForSingleValueEvent(new ValueEventListener() {
                @Override
                public void onDataChange(DataSnapshot dataSnapshot) {
                    for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
                        User user = snapshot.getValue(User.class);
                        System.out.println(user.email);
                    }
                }
                @Override
                public void onCancelled(DatabaseError databaseError) {
                }
            });

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=448050&siteId=1