How to list the registered users names in Android (Firebase)?

前端 未结 2 593
青春惊慌失措
青春惊慌失措 2021-01-27 16:09

I am new to android and just learned to create a users profile like facebook or instagram, currently I have registered four users with email/password and in database am storing

相关标签:
2条回答
  • 2021-01-27 16:36

    Firebase is NoSql. You need to retrieve all users from myRef.child("users") and apply iterator to get names of all users.

    0 讨论(0)
  • 2021-01-27 16:40

    To display those names, please use this code:

    DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
    DatabaseReference usersdRef = rootRef.child("users");
    ValueEventListener eventListener = new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            for(DataSnapshot ds : dataSnapshot.getChildren()) {
                String name = ds.child("name").getValue(String.class);
                Log.d("TAG", name);
            }
        }
    
        @Override
        public void onCancelled(DatabaseError databaseError) {}
    };
    usersdRef.addListenerForSingleValueEvent(eventListener);
    

    And the output will be in this case all your user names.

    0 讨论(0)
提交回复
热议问题