title: Android Navigation Drawer Set Title
body: <p>I want to change the title of my Navigation Drawer when a user clicks on the particular fragment of the navigation drawer. I'm new to the world of Android Programming. So please kindly help Below is my code</p>
  
  <p>Main Activity Code</p>
  
  <pre><code>    package com.androidbelieve.HIT_APP;
  
  import android.os.Bundle;
  import android.support.design.widget.NavigationView;
  import android.support.v4.app.Fragment;
  import android.support.v4.app.FragmentManager;
  import android.support.v4.app.FragmentTransaction;
  import android.support.v4.widget.DrawerLayout;
  import android.support.v7.app.ActionBarDrawerToggle;
  import android.support.v7.app.AppCompatActivity;
  import android.view.MenuItem;
  
  public class MainActivity extends AppCompatActivity{
      DrawerLayout mDrawerLayout;
      NavigationView mNavigationView;
      FragmentManager mFragmentManager;
      FragmentTransaction mFragmentTransaction;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          /**
           *Setup the DrawerLayout and NavigationView
           */
  
          mDrawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
          mNavigationView = (NavigationView) findViewById(R.id.shitstuff) ;
  
  
  
  
          /**
           * Lets inflate the very first fragment
           * Here , we are inflating the TabFragment as the first Fragment
           */
  
          mFragmentManager = getSupportFragmentManager();
          mFragmentTransaction = mFragmentManager.beginTransaction();
          // mFragmentTransaction.replace(R.id.containerView,new TabFragment()).commit();
          mFragmentTransaction.replace(R.id.containerView,new HomeFragment()).commit();
  
  
          /**
           * Setup click events on the Navigation View Items.
           */
  
          mNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
              @Override
              public boolean onNavigationItemSelected(MenuItem menuItem) {
                  mDrawerLayout.closeDrawers();
  
  
  
  
                if (menuItem.getItemId() == R.id.nav_item_home) {
                      FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
                      fragmentTransaction.replace(R.id.containerView,new HomeFragment()).commit();
  
                  }
  
                  if (menuItem.getItemId() == R.id.nav_item_dept) {
                      FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
                      fragmentTransaction.replace(R.id.containerView,new DeptFragment()).commit();
  
                  }
  
                  if (menuItem.getItemId() == R.id.nav_item_facility) {
                      FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
                      fragmentTransaction.replace(R.id.containerView,new FacilityFragment()).commit();
  
                  }
  
                  if (menuItem.getItemId() == R.id.nav_item_placement) {
                      FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
                      fragmentTransaction.replace(R.id.containerView,new PlacementFragment()).commit();
  
                  }
  
                  if (menuItem.getItemId() == R.id.nav_item_gallery) {
                      FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
                      fragmentTransaction.replace(R.id.containerView,new GalleryFragment()).commit();
  
                  }
  
                  if (menuItem.getItemId() == R.id.nav_item_developer) {
                      FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
                      fragmentTransaction.replace(R.id.containerView,new DeveloperFragment()).commit();
  
                  }
  
  
  
                  if (menuItem.getItemId() == R.id.nav_item_near) {
                      FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
                      fragmentTransaction.replace(R.id.containerView,new NearFragment()).commit();
  
                  }
  
  
                  if (menuItem.getItemId() == R.id.nav_item_notify) {
                      FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
                      fragmentTransaction.replace(R.id.containerView,new NotifyFragment()).commit();
  
                  }
  
                  if (menuItem.getItemId() == R.id.nav_item_vtu) {
                      FragmentTransaction xfragmentTransaction = mFragmentManager.beginTransaction();
                      xfragmentTransaction.replace(R.id.containerView,new TabFragment()).commit();
                  }
  
  
                  return false;
  
              }
  
  
  
          });
  
          /**
           * Setup Drawer Toggle of the Toolbar
           */
  
          android.support.v7.widget.Toolbar toolbar = (android.support.v7.widget.Toolbar) findViewById(R.id.toolbar);
          ActionBarDrawerToggle mDrawerToggle = new ActionBarDrawerToggle(this,mDrawerLayout, toolbar,R.string.app_name,
                  R.string.app_name);
  
          mDrawerLayout.setDrawerListener(mDrawerToggle);
  
          mDrawerToggle.syncState();
  
      }
  }
  </code></pre>
  
  <p>I think something needs to be done here itself when a person selects any of the drawer items. </p>
  
  <p>Any other piece of code required let me know</p>