title: Navigation Drawer Header how to put name and profile pic image from Google Sign in
body: <p>I was able to make a navigation drawer and google sign in app using firebase tutorials from youtube <a href="https://www.youtube.com/playlist?list=PLGCjwl1RrtcR1j6EmpBxJyJYowK2QIsdT" rel="nofollow noreferrer">https://www.youtube.com/playlist?list=PLGCjwl1RrtcR1j6EmpBxJyJYowK2QIsdT</a></p>
  
  <p>I have <strong>activity_navigation.xml</strong>:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:id="@+id/drawerLayout"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context="rjbc.cpvc.NavigationActivity"&gt;
  
      &lt;LinearLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="vertical"&gt;
  
          &lt;include layout = "@layout/navigation_action"
              android:layout_height="wrap_content"
              android:layout_width="match_parent" /&gt;
  
          &lt;RelativeLayout
              android:layout_width="match_parent"
              android:layout_height="match_parent"&gt;
  
              &lt;TextView
                  android:text="TextView"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_alignParentTop="true"
                  android:layout_alignParentStart="true"
                  android:layout_marginStart="101dp"
                  android:layout_marginTop="201dp"
                  android:id="@+id/textView5" /&gt;
  
              &lt;ImageView
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  app:srcCompat="@mipmap/ic_person_black_24dp"
                  android:layout_below="@+id/textView5"
                  android:layout_alignEnd="@+id/textView5"
                  android:layout_marginEnd="42dp"
                  android:layout_marginTop="53dp"
                  android:id="@+id/imageView" /&gt;
          &lt;/RelativeLayout&gt;
      &lt;/LinearLayout&gt;    
  
      &lt;android.support.design.widget.NavigationView
          android:id="@+id/nav_view"
          android:layout_width="wrap_content"
          android:layout_height="match_parent"
          app:menu="@menu/navigation_menu"
          android:layout_gravity = "start"
          app:headerLayout="@layout/navigation_header" /&gt;
  
  &lt;/android.support.v4.widget.DrawerLayout&gt;
  </code></pre>
  
  <p>and <strong>navigation_header.xml</strong>:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout 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="140dp"
      android:background="@color/colorPrimary"
      android:padding="20dp"
      android:id="@+id/pName"&gt;
  
      &lt;TextView
          android:text="TextView"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginBottom="13dp"
          android:id="@+id/textView"
          android:layout_alignParentBottom="true"
          android:layout_alignParentStart="true"
          android:textColor="@color/common_google_signin_btn_text_dark_default" /&gt;
  
      &lt;ImageView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          app:srcCompat="@mipmap/ic_person_black_24dp"
          android:id="@+id/pPic"
          android:layout_above="@+id/textView"
          android:layout_alignEnd="@+id/textView"
          android:layout_marginEnd="16dp"
          android:layout_marginBottom="18dp" /&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p><strong>this is my navigation_activity.java</strong></p>
  
  <pre><code>public class NavigationActivity extends AppCompatActivity {
      private DrawerLayout mDrawerLayout;
      private ActionBarDrawerToggle mToggle;
      private Toolbar mToolbar;
  
      private FirebaseAuth mAuth;
      private FirebaseAuth.AuthStateListener mAuthListener;
      private TextView mName;
  
      private String name;
      private Uri photoUrl;
      private ImageView mPic;
  
      private NavigationView mNavigationView;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_navigation);
          mToolbar = findViewById(R.id.nav_action);
          setSupportActionBar(mToolbar);
          mDrawerLayout = findViewById(R.id.drawerLayout);
          mToggle = new ActionBarDrawerToggle(this,mDrawerLayout,R.string.open,R.string.close);
  
          mDrawerLayout.addDrawerListener(mToggle);
          mToggle.syncState();
  
          getSupportActionBar().setDisplayHomeAsUpEnabled(true);
  
          mAuth = FirebaseAuth.getInstance();
          mAuthListener = new FirebaseAuth.AuthStateListener() {
              @Override
              public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
                  if(firebaseAuth.getCurrentUser() == null) {
                      startActivity(new Intent(NavigationActivity.this,MainActivity.class));
                  }
              }
          };
  
          mName = mNavigationView.getHeaderView(0).findViewById(R.id.textView);
          mPic = mNavigationView.getHeaderView(0).findViewById(R.id.pPic);
          getCurrentinfo();
  
          mNavigationView = findViewById(R.id.nav_view);
  
          mNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
              @Override
              public boolean onNavigationItemSelected(final MenuItem menuItem) {
  
                  int id = menuItem.getItemId();
                  switch (id) {
                      case R.id.nav_account:
                          Toast.makeText(NavigationActivity.this, "Account Selected", Toast.LENGTH_SHORT).show();
                          return true;
  
                      case R.id.nav_settings:
                          Toast.makeText(NavigationActivity.this, "Setting Selected", Toast.LENGTH_SHORT).show();
  
                      default:
                          return true;
                  }
              }
          });
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          if(mToggle.onOptionsItemSelected(item)) {
              return true;
          }
          return super.onOptionsItemSelected(item);
      }
  
      private void getCurrentinfo() {
          FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
          if (user != null) {
              for (UserInfo profile : user.getProviderData()) {
                  // Id of the provider (ex: google.com)
                  String providerId = profile.getProviderId();
  
                  // UID specific to the provider
                  String uid = profile.getUid();
  
                  // Name, email address, and profile photo Url
                  name = profile.getDisplayName();
                  photoUrl = profile.getPhotoUrl();
                  mName.setText(name);
  
                  Picasso.with(getApplicationContext())
                          .load(photoUrl.toString())
                          .placeholder(R.drawable.logo)
                          .resize(100, 100)
                          .transform(new CircleTransform())
                          .centerCrop()
                          .into(mPic);    
              }
          }
      }
  }
  </code></pre>
  
  <p>in my <code>getcurrentInfo</code> function I am able to place my name and profile pic in the <code>activity_navigation.xml</code> but I want to place it an <code>navigation_header.xml</code> </p>
  
  <p>I tried changing the id of my <code>ImageView</code> and <code>TextView</code> to match with that in the <code>navigation_header</code> but my app crashes. </p>