I'm trying to display the name of my current user inside an menu item, I am getting the username like this
DatabaseReference ref = FirebaseDatabase.getInstance().getReference();
DatabaseReference name =
ref.child("Users").child(mCurrentUser.getUid()).child("name");
name.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
String username = dataSnapshot.getValue(String.class);
username2 = username; //should i be doing this? how can i pass username
//directly to other other methods in the code?
}
and it works fine because i have tested it with toasts, however when i pass username2
to the setTitle method it does not display it. If i pass anything else inside it, it works just fine. If i pass username2
+ something else it displays nullsomething else
NavigationView navigationView = (NavigationView)
findViewById(R.id.navmenuffs);
Menu menu = navigationView.getMenu();
MenuItem nav_profile = menu.findItem(R.id.nav_profile);
nav_profile.setTitle(username2);
username2
is just a String I have declared public so i can use username
in other methods