Show the name of all users in my database

-6

Hello, what I need is to show the name of the users that I have in my Database, but I can not do it, could you help me please.

Each one is referenced by the user's password, thank you very much.

 database = FirebaseDatabase.getInstance();
    addU = database.getReference(bdreference.userRefence);
    addU.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {

            key= dataSnapshot.getKey();
            nombre=dataSnapshot.child(key).child("nombre").getValue(String.class);
                Log.i("nombre",nombre);
        }
        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });
    
asked by devlp 12.12.2017 в 09:03
source

2 answers

1

Your thing is that you look at the documentation about how to recover data. Basically what you have to do is recover the users table, and within it, iterate its rows and play with the fields it has:

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

            Map<String, String> map = (Map<String, String>) dataSnapshot.getValue();
            String nombre = map.get("nombre");

            // hacer algo con el NOMBRE

        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
});
    
answered by 12.12.2017 в 11:45
-1

As the partner says above, to get the user's data is easy, just that you need to add the getUid to get the user, where it says child ("users") is the branch from where it comes, let's say it's the key that includes all the Users ID, if you do not have it you get the child part ("users") and you must declare a mAuth to identify the user that you want to get the name. Now, if you need to recover only those three, I recommend you concatenate the addValueEventListener with different dataSnapShot.

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


      String NombreUsuario=dataSnapshot.getValue().toString();
                    Log.e("Nombre de usuario", "" + NombreUsuario);



            }

            @Override
            public void onCancelled(DatabaseError databaseError) {

            }
        });

I hope you serve

    
answered by 12.12.2017 в 16:25