0

Although this question is from basics. I want print the all the childs of users in recycler view how to do that the firebase looks like this

Root
        |
        |_users
                    |
                    |_john
                    |_paul
                    |_//other names....
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • **[This](https://stackoverflow.com/questions/49383687/how-can-i-retrieve-data-from-firebase-to-my-adapter/49384849)** is a recommended way in which you can retrieve data from a Firebase Realtime database and display it in a `RecyclerView` using `FirebaseRecyclerAdapter`. – Alex Mamo Nov 18 '18 at 11:45
  • Possible duplicate of [How can I retrieve data from Firebase to my adapter](https://stackoverflow.com/questions/49383687/how-can-i-retrieve-data-from-firebase-to-my-adapter) – Nick Dec 01 '18 at 01:34

1 Answers1

1

Try as follows

DatabaseReference mDatabase;

mDatabase = FirebaseDatabase.getInstance().getReference();
DatabaseReference mRef = mDatabase.getReference();


mDatabase.child("users").addValueEventListener(new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot dataSnapshot) {

        for (DataSnapshot postSnapshot: snapshot.getChildren()) {
            String name = postSnapshot.getValue();
            //do what you want
    }

    @Override
    public void onCancelled(DatabaseError error) {
        // Failed to read value
        Log.w(TAG, "Failed to read value.", error.toException());
    }
});