title: Unable to Get Navigation Drawer Items to Display Items Correctly
body: <p>I have got a working Navigation drawer in a blank project, however whenever I try to implement the navigation drawer in to an existing project, it doesn't seem to be working properly. </p>
  
  <p>The navigation drawer displays fine, however, when items inside are selected, it doesn't seem to redirect to the fragment selected.</p>
  
  <p>I have tried using many resources, however, I am still unable to progress.</p>
  
  <p>Thanks in advance.</p>
  
  <p>Here is my code below:</p>
  
  <p><strong>NavigationDrawer Class</strong></p>
  
  <pre><code>import android.net.Uri;
  import android.os.Bundle;
  import android.support.design.widget.NavigationView;
  import android.support.v4.app.Fragment;
  import android.support.v4.app.FragmentTransaction;
  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;
  import android.view.View;
  import android.widget.AbsListView;
  
  
  
  
  public class NDrawer extends AppCompatActivity
      implements NavigationView.OnNavigationItemSelectedListener,
  About.OnFragmentInteractionListener, Home.OnFragmentInteractionListener {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
          setSupportActionBar(toolbar);
          Fragment fragment;
  
          NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
          navigationView.setNavigationItemSelectedListener(this);
  
          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();
  
  
                  }
  
      @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.main, 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();
          Fragment fragment;
  
          if (id == R.id.nav_home) {
              fragment = new Home();
              FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
              ft.replace(R.id.content_frame, fragment);
              ft.detach(fragment);
              ft.attach(fragment);
              ft.commit();
  
          } else if (id == R.id.nav_rooms) {
  
          } else if (id == R.id.nav_account) {
  
          } else if (id == R.id.nav_settings) {
  
          } else if (id == R.id.nav_help) {
  
          } else if (id == R.id.nav_about) {
              fragment = new About();
              FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
              ft.replace(R.id.content_frame, fragment);
              ft.detach(fragment);
              ft.attach(fragment);
              ft.commit();
  
  
          } else if (id == R.id.nav_signout) {
          }
  
          DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
          drawer.closeDrawer(GravityCompat.START);
          return true;
      }
  
  
      @Override
      public void onFragmentInteraction(Uri uri) {
  
      }
  
  
      }
  </code></pre>
  
  <p><strong>About Fragment Class</strong></p>
  
  <pre><code>import android.content.Context;
  import android.net.Uri;
  import android.os.Bundle;
  import android.support.v4.app.Fragment;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  
  
  /**
   * A simple {@link Fragment} subclass.
   * Activities that contain this fragment must implement the
   * {@link About.OnFragmentInteractionListener} interface
   * to handle interaction events.
   * Use the {@link About#newInstance} factory method to
   * create an instance of this fragment.
   */
  
  public class About extends Fragment {
  
  // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
  private static final String ARG_PARAM1 = "param1";
  private static final String ARG_PARAM2 = "param2";
  
  
  private String mParam1;
  private String mParam2;
  
  private OnFragmentInteractionListener mListener;
  
  public About() {
      // Required empty public constructor
  }
  
  /**
   * Use this factory method to create a new instance of
   * this fragment using the provided parameters.
   *
   * @param param1 Parameter 1.
   * @param param2 Parameter 2.
   * @return A new instance of fragment About.
   */
  
  public static About newInstance(String param1, String param2) {
      About fragment = new About();
      Bundle args = new Bundle();
      args.putString(ARG_PARAM1, param1);
      args.putString(ARG_PARAM2, param2);
      fragment.setArguments(args);
      return fragment;
  }
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      if (getArguments() != null) {
          mParam1 = getArguments().getString(ARG_PARAM1);
          mParam2 = getArguments().getString(ARG_PARAM2);
      }
      }
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
      // Inflate the layout for this fragment
      return inflater.inflate(R.layout.activity_about, container, false);
  }
  
  
  public void onButtonPressed(Uri uri) {
      if (mListener != null) {
          mListener.onFragmentInteraction(uri);
      }
  }
  
  @Override
  public void onAttach(Context context) {
      super.onAttach(context);
      if (context instanceof OnFragmentInteractionListener) {
          mListener = (OnFragmentInteractionListener) context;
      } else {
          throw new RuntimeException(context.toString()
                  + " must implement OnFragmentInteractionListener");
      }
  }
  
  @Override
  public void onDetach() {
      super.onDetach();
      mListener = null;
  }
  
  /**
   * This interface must be implemented by activities that contain this
   * fragment to allow an interaction in this fragment to be communicated
   * to the activity and potentially other fragments contained in that
   * activity.
   * &lt;p/&gt;
   * See the Android Training lesson &lt;a href=
   * "http://developer.android.com/training/basics/fragments/communicating.html"
   * &gt;Communicating with Other Fragments&lt;/a&gt; for more information.
   */
  public interface OnFragmentInteractionListener {
  
      void onFragmentInteraction(Uri uri);
  }
  }
  </code></pre>
  
  <p><strong>activity_main.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:app="http://schemas.android.com/apk/res-auto"
      xmlns:tools="http://schemas.android.com/tools"
      android:id="@+id/drawer_layout"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:fitsSystemWindows="true"
      tools:openDrawer="start"&gt;
  
  
  
      &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          xmlns:tools="http://schemas.android.com/tools"
          android:gravity="center"
          android:orientation="vertical"
          android:padding="10dp"
          android:paddingLeft="16dp"
          android:paddingRight="16dp"
          tools:context=".UserActivity"&gt;
  
  
          &lt;TextView
              style="@style/Base.TextAppearance.AppCompat.Headline"
              android:id="@+id/displayUsername"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:padding="5dp"
              android:layout_margin="5dp"/&gt;
  
          &lt;Button
              android:id="@+id/listen_button"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="Listen"
              android:onClick="buttonClicked"
              /&gt;
  
  
          &lt;TextView
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:text=""
              android:id="@+id/textView"
              /&gt;
  
          &lt;TextView
              android:id="@+id/status"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:text="" /&gt;
  
          &lt;TextView
              style="@style/Base.TextAppearance.AppCompat.Headline"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_gravity="center_horizontal"
              android:text="@string/signed_in_header" /&gt;
  
          &lt;Button android:id="@+id/btn_settings"
              android:text="@string/settings"
              android:layout_marginTop="40dp"
              android:layout_width="190dp"
              android:layout_height="45dp"
              android:onClick="buttonClicked" /&gt;
  
  
          &lt;Button android:id="@+id/btn_sign_out"
              android:text="@string/sign_out"
              android:layout_marginTop="40dp"
              android:layout_width="190dp"
              android:layout_height="45dp"
              android:onClick="buttonClicked" /&gt;
  
          &lt;TextView
              android:id="@+id/displayUsername2"
              android:layout_width="242dp"
              android:layout_height="34dp"
              android:padding="5dp"
              android:layout_margin="5dp"/&gt;
  
  
      &lt;/LinearLayout&gt;
  
      &lt;include
          layout="@layout/app_bar_nav"
          android:layout_width="match_parent"
          android:layout_height="match_parent" /&gt;
  
      &lt;android.support.design.widget.NavigationView
          android:id="@+id/nav_view"
          android:layout_width="wrap_content"
          android:layout_height="match_parent"
          android:layout_gravity="start"
          android:fitsSystemWindows="true"
          app:headerLayout="@layout/nav_header_nav"
          app:menu="@menu/activity_nav_drawer" /&gt;
  
  
  &lt;/android.support.v4.widget.DrawerLayout&gt;
  </code></pre>
  
  <p><strong>activity_nav_drawer.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;menu xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      tools:showIn="navigation_view"&gt;
  
  +6   &lt;group android:checkableBehavior="single"&gt;
  
      &lt;item
          android:id="@+id/nav_home"
          android:icon="@drawable/ic_home"
          android:checked="true"
          android:title="Home" /&gt;
      &lt;item
          android:id="@+id/nav_rooms"
          android:icon="@drawable/ic_room_black"
          android:title="All Rooms" /&gt;
      &lt;item
          android:id="@+id/nav_account"
          android:icon="@drawable/ic_account_box_black"
          android:title="Account" /&gt;
      &lt;item
          android:id="@+id/nav_settings"
          android:icon="@drawable/ic_settings_black"
          android:title="Settings" /&gt;
  
      &lt;item
          android:id="@+id/nav_help"
          android:icon="@drawable/ic_help_black"
          android:title="Help" /&gt;
  
      &lt;item
          android:id="@+id/nav_about"
          android:title="About" /&gt;
  
       &lt;item
           android:id="@+id/nav_signout"
           android:icon="@drawable/ic_input_black"
           android:title="Logout" /&gt;
  &lt;/group&gt;
  
  &lt;/menu&gt;
  </code></pre>
  
  <p><strong>content_main.xml</strong></p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;android.support.constraint.ConstraintLayout 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="match_parent"
      app:layout_behavior="@string/appbar_scrolling_view_behavior"
      tools:context=".NDrawer"
      tools:showIn="@layout/app_bar_nav"&gt;
  
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          app:layout_constraintBottom_toBottomOf="parent"
          app:layout_constraintLeft_toLeftOf="parent"
          app:layout_constraintRight_toRightOf="parent"
          app:layout_constraintTop_toTopOf="parent" /&gt;
  
      &lt;LinearLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:id="@+id/content_frame"
          android:orientation="horizontal" /&gt;
  &lt;/android.support.constraint.ConstraintLayout&gt;
  </code></pre>
  
  <p><strong>app_bar_nav.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;android.support.design.widget.CoordinatorLayout 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="match_parent"
      tools:context="aviraj.firebaseapp.NDrawer"&gt;
  
      &lt;android.support.design.widget.AppBarLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:theme="@style/AppTheme.AppBarOverlay"&gt;
  
          &lt;android.support.v7.widget.Toolbar
              android:id="@+id/toolbar"
              android:layout_width="match_parent"
              android:layout_height="?attr/actionBarSize"
              android:background="?attr/colorPrimary"
              app:popupTheme="@style/AppTheme.PopupOverlay" /&gt;
  
      &lt;/android.support.design.widget.AppBarLayout&gt;
  
      &lt;include layout="@layout/content_main" /&gt;
  
  &lt;/android.support.design.widget.CoordinatorLayout&gt;
  </code></pre>