title: How can I retrieve Logged user data to nav header as Username in Android studio project with Firebase
body: <p>I'm new for Android Project. I create project with Firebase. In this project I want to add Logged User name's to textview in nav header. I use for login or registration Model options.  But I can't. 
  Does anyone have any experience with this? My firebase database datas shown like this. <a href="https://i.stack.imgur.com/UMOli.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UMOli.png" alt="enter image description here"></a> </p>
  
  <p>I want make like this 
  <a href="https://i.stack.imgur.com/on9Mu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/on9Mu.png" alt="enter image description here"></a></p>
  
  <p>My Home Activity is this</p>
  
  <pre><code>package com.cavad.firebaseproject;
  
  import android.os.Bundle;
  import android.support.annotation.NonNull;
  import android.support.v4.app.Fragment;
  import android.support.v4.app.FragmentManager;
  import android.support.v4.app.FragmentTransaction;
  import android.support.design.widget.NavigationView;
  import android.support.v4.view.GravityCompat;
  import android.support.v4.widget.DrawerLayout;
  import android.support.v7.app.ActionBarDrawerToggle;
  import android.support.v7.app.AppCompatActivity;
  import android.support.v7.widget.Toolbar;
  import android.view.Menu;
  import android.view.MenuItem;
  
  
  public class Home extends AppCompatActivity
      implements NavigationView.OnNavigationItemSelectedListener {
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_home);
      Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
      setSupportActionBar(toolbar);
  
      DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
      ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
              this, drawer, toolbar, R.string.navigation_drawer_open, 
   R.string.navigation_drawer_close);
      drawer.addDrawerListener(toggle);
      toggle.syncState();
  
      NavigationView navigationView = (NavigationView) 
   findViewById(R.id.nav_view);
      navigationView.setNavigationItemSelectedListener(this);
  
      Fragment category = new CategoryFragment();
      this.setDefaultFragment(category);
   }
  
   private void setDefaultFragment(Fragment defaultFragment)
   {
      this.replaceFragment(defaultFragment);
   }
  
   public void replaceFragment(Fragment destFragment)
   {
      FragmentManager fragmentManager = this.getSupportFragmentManager();
      FragmentTransaction fragmentTransaction = 
   fragmentManager.beginTransaction();
      fragmentTransaction.replace(R.id.category, destFragment);
      fragmentTransaction.commit();
   }
  
  @Override
  public void onBackPressed() {
      DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
      if (drawer.isDrawerOpen(GravityCompat.START)) {
          drawer.closeDrawer(GravityCompat.START);
      } else {
          super.onBackPressed();
      }
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.home, menu);
      return true;
    }
  
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
      // Handle action bar item clicks here. The action bar will
      // automatically handle clicks on the Home/Up button, so long
      // as you specify a parent activity in AndroidManifest.xml.
      int id = item.getItemId();
  
      //noinspection SimplifiableIfStatement
      if (id == R.id.action_settings) {
          return true;
      }
  
      return super.onOptionsItemSelected(item);
  }
  
  @SuppressWarnings("StatementWithEmptyBody")
  @Override
  public boolean onNavigationItemSelected(MenuItem item) {
      // Handle navigation view item clicks here.
      int id = item.getItemId();
  
      if (id == R.id.nav_camera) {
          // Handle the camera action
      } else if (id == R.id.nav_gallery) {
  
      } else if (id == R.id.nav_slideshow) {
  
      } else if (id == R.id.nav_manage) {
  
      } else if (id == R.id.nav_share) {
  
      } else if (id == R.id.nav_send) {
  
      }
  
      DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
      drawer.closeDrawer(GravityCompat.START);
      return true;
    }
   }
  </code></pre>
  
  <p>My nav_header xml file is this nav_header_home.xml //</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:background="@color/colorPrimaryDark"
  android:gravity="bottom"
  android:orientation="vertical"
  android:paddingLeft="@dimen/activity_horizontal_margin"
  android:paddingTop="@dimen/activity_vertical_margin"
  android:paddingRight="@dimen/activity_horizontal_margin"
  android:paddingBottom="@dimen/activity_vertical_margin"
  android:theme="@style/ThemeOverlay.AppCompat.Dark"&gt;
  
  &lt;TextView
      android:id="@+id/userName"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_gravity="center"
      android:gravity="center"
      android:text="userName"
      android:textColor="@color/white"
      android:textSize="20sp"
      android:layout_marginTop="15dp"
      android:layout_marginBottom="10dp"
      android:textStyle="bold"/&gt;
  
  &lt;/LinearLayout&gt;   
  </code></pre>
  
  <p>My Model class is this</p>
  
  <pre><code> package com.cavad.firebaseproject.Model;
  
  public class User {
  
  private String userName;
  private String password;
  private String email;
  
  public User(){
  }
  
  public User(String userName, String password, String email) {
      this.userName = userName;
      this.password = password;
      this.email = email;
  }
  
  public String getUserName() {
      return userName;
  }
  
  public void setUserName(String userName) {
      this.userName = userName;
  }
  
  public String getPassword() {
      return password;
  }
  
  public void setPassword(String password) {
      this.password = password;
  }
  
  public String getEmail() {
      return email;
  }
  
  public void setEmail(String email) {
      this.email = email;
  }
  }
  </code></pre>
  
  <p>My Firebase database rules is this</p>
  
  <pre><code>  {
      "rules": {
      ".read": true,
      ".write": true
      }
     }
  </code></pre>
  
  <p>My Login activity is this</p>
  
  <pre><code> package com.cavad.firebaseproject;
  
   import android.content.Intent;
   import android.os.Bundle;
   import android.support.annotation.NonNull;
   import android.support.v4.app.Fragment;
   import android.view.LayoutInflater;
   import android.view.View;
   import android.view.ViewGroup;
   import android.widget.EditText;
   import android.widget.ImageView;
   import android.widget.Toast;
  
   import com.cavad.firebaseproject.Model.User;
   import com.google.firebase.database.DataSnapshot;
   import com.google.firebase.database.DatabaseError;
   import com.google.firebase.database.DatabaseReference;
   import com.google.firebase.database.FirebaseDatabase;
   import com.google.firebase.database.ValueEventListener;
  public class Login extends Fragment {
  
  EditText user, password;
  ImageView signin;
  
  FirebaseDatabase database;
  DatabaseReference users;
  
  public Login() {
  
  }
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
      // Inflate the layout for this fragment
      View view = inflater.inflate(R.layout.fragment_login, container, 
   false);
  
      database = FirebaseDatabase.getInstance();
      users = database.getReference("Users");
  
      user = view.findViewById(R.id.name);
      password = view.findViewById(R.id.password);
      signin = view.findViewById(R.id.submit);
  
      signin.setOnClickListener(new View.OnClickListener(){
          @Override
          public void onClick(View v){
  
    signin(user.getText().toString(),password.getText().toString());
          }
      });
  
      return view;
     }
    private void signin(final String user, final String pwd){
      users.addListenerForSingleValueEvent(new ValueEventListener() {
          @Override
          public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
              if (dataSnapshot.child(user).exists())
              {
                  if (!user.isEmpty())
                  {
                      User login = 
    dataSnapshot.child(user).getValue(User.class);
                      if (login.getPassword().equals(pwd))
                      {
                          Toast.makeText(getActivity(), "Uğurla daxil 
   oldunuz", Toast.LENGTH_SHORT).show();
                          startActivity(new 
   Intent(getActivity().getApplication(), Home.class));
  
                      }
                      else
                          Toast.makeText(getActivity(), "Zəhmət olmasa 
   Şifrəni düzgün daxil edin", Toast.LENGTH_SHORT).show();
                  }
                  else
                  {
                      Toast.makeText(getActivity(), "Zəhmət olmasa 
   İstifadəçi adınızı daxil edin", Toast.LENGTH_SHORT).show();
                  }
              }
              else
                  Toast.makeText(getActivity(), "Belə bir istifadəçi adı 
     tapılmadı !!!", Toast.LENGTH_SHORT).show();
          }
  
          @Override
          public void onCancelled(@NonNull DatabaseError databaseError) {
  
          }
      });
    }
   }
  </code></pre>
  
  <p>My Login acticity xml is this</p>
  
  <pre><code> &lt;LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  tools:context=".Login"
  android:background="@color/colorPrimaryDark"
  android:orientation="vertical"&gt;
  
  &lt;LinearLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:orientation="horizontal"
      android:weightSum="2"
      android:layout_marginTop="7dp"
      android:layout_marginBottom="7dp"&gt;
  
      &lt;LinearLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:orientation="vertical"&gt;
  
          &lt;android.support.design.widget.TextInputLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_marginTop="7dp"
              android:layout_marginBottom="7dp"
              app:hintEnabled="false"
              android:layout_marginLeft="20dp"
              android:layout_marginRight="20dp"&gt;
  
              &lt;EditText
                  android:id="@+id/name"
                  android:layout_width="match_parent"
                  android:layout_height="48dp"
                  android:hint="@string/name"
                  android:inputType="text"
                  android:textSize="20sp"
                  android:drawableStart="@drawable/ic_user"
                  android:drawableLeft="@drawable/ic_user"
                  android:drawablePadding="10dp"
                  android:background="@drawable/edttext_background"
                  android:paddingRight="10dp"
                  android:paddingLeft="10dp"/&gt;
          &lt;/android.support.design.widget.TextInputLayout&gt;
  
          &lt;android.support.design.widget.TextInputLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_marginTop="7dp"
              android:layout_marginBottom="7dp"
              app:hintEnabled="false"
              app:passwordToggleDrawable="@drawable/visibility"
              app:passwordToggleEnabled="true"
              android:layout_marginLeft="20dp"
              android:layout_marginRight="20dp"&gt;
  
              &lt;EditText
                  android:id="@+id/password"
                  android:layout_width="match_parent"
                  android:layout_height="48dp"
                  android:textSize="20sp"
                  android:inputType="textPassword"
                  android:hint="@string/password"
                  android:drawableStart="@drawable/ic_lock"
                  android:drawableLeft="@drawable/ic_lock"
                  android:background="@drawable/edttext_background"
                  android:drawablePadding="10dp"
                  android:paddingRight="10dp"
                  android:paddingLeft="10dp" /&gt;
          &lt;/android.support.design.widget.TextInputLayout&gt;
  
          &lt;ImageView
              android:id="@+id/submit"
              android:layout_width="48dp"
              android:layout_height="48dp"
              android:gravity="center"
              android:layout_gravity="center"
              android:src="@drawable/ic_check"
              android:background="@drawable/check_background"
              android:layout_marginTop="15dp"
              android:layout_marginBottom="15dp"/&gt;
  
      &lt;/LinearLayout&gt;
  
  &lt;/LinearLayout&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>