Skip to content Skip to sidebar Skip to footer

How Do I Get String List Of Username And Fullname From Firebase?

In java class, I used some random username and fullname for testing but now I want to get the list of username and full name of user who are child of current user in Mates node in

Solution 1:

According to your comment, to get all user objects that exist within Mates/uid, please use the following lines of code:

Stringuid= FirebaseAuth.getInstance().getCurrentUser().getUid();
DatabaseReferencerootRef= FirebaseDatabase.getInstance().getReference();
DatabaseReferenceuidRef= rootRef.child("Mates").child(uid);
ValueEventListenervalueEventListener=newValueEventListener() {
    @OverridepublicvoidonDataChange(DataSnapshot dataSnapshot) {
        List<User> userList = newArrayList<>();
        for(DataSnapshot ds : dataSnapshot.getChildren()) {
            Useruser= ds.getValue(User.class);
            userList.add(user);
            Log.d(TAG, user.getUsername() + " / " + user.getFullname());
        }

        //Do what you need to do with your userList
    }

    @OverridepublicvoidonCancelled(@NonNull DatabaseError databaseError) {
        Log.d(TAG, databaseError.getMessage()); //Don't ignore errors!
    }
};
uidRef.addListenerForSingleValueEvent(valueEventListener);

The output in the logcat will be all usernames and fullnames of all users that exist within the uid.

Solution 2:

make it clear you want to replace full name , username from java class to firebase. right ?

Post a Comment for "How Do I Get String List Of Username And Fullname From Firebase?"