title: creating base activity with navigation drawer in android
body: <p>I tried to follow <a href="https://stackoverflow.com/questions/4922641/sliding-drawer-appear-in-all-activities">this</a> answer, with the main idea is to override the <code>setContentView</code> in the <code>BaseActivity</code>, the activity that will be extended by all activity so only <code>BaseActivity</code> will have the navigation drawer. </p>
  
  <p>However, my navigation is never shown (even in <code>BaseActivity</code>) after i tried to implement the answer. This is what i did :</p>
  
  <p>This is the navigation drawer's xml :</p>
  
  <pre><code>&lt;android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/drawer_layout"
      android:layout_width="match_parent"
      android:layout_height="match_parent" &gt;
  
      &lt;!-- Framelayout to display Fragments --&gt;
  
      &lt;FrameLayout
          android:id="@+id/frame_container"
          android:layout_width="match_parent"
          android:layout_height="match_parent" /&gt;
  
      &lt;!-- Listview to display slider menu --&gt;
  
      &lt;ListView
          android:id="@+id/list_slidermenu"
          android:layout_width="120dp"
          android:layout_height="match_parent"
          android:layout_gravity="start"
          android:background="@color/list_background"
          android:choiceMode="singleChoice"
          android:divider="@color/list_divider"
          android:dividerHeight="1dp"
          android:listSelector="@drawable/list_selector" /&gt;
  
  &lt;/android.support.v4.widget.DrawerLayout&gt;
  </code></pre>
  
  <p>This is my overrided <code>setContentView</code> (in <code>BaseActivity</code>) :</p>
  
  <pre><code>@Override
      public void setContentView(int layoutResID) {
          // TODO Auto-generated method stub
          mDrawerLayout= (DrawerLayout) getLayoutInflater().inflate(R.layout.activity_main, null); // Your base layout here
          actContent= (FrameLayout) mDrawerLayout.findViewById(R.id.frame_container);
          //listLayout = (LinearLayout) mDrawerLayout.findViewById(R.id.listLayout);
          getLayoutInflater().inflate(layoutResID, actContent, true);
          //getLayoutInflater().inflate(layoutResID, listLayout, true);
          super.setContentView(layoutResID);
      }
  </code></pre>
  
  <p>And this is my <code>onCreate</code> on <code>BaseActivity</code>, note that i use <code>getLayoutInflater().inflate</code> instead of <code>setContentView</code> :</p>
  
  <pre><code>@Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          //setContentView(R.layout.activity_main);
  
          //getSupportActionBar().setDisplayShowHomeEnabled(false);
          //getSupportActionBar().setDisplayShowCustomEnabled(true);
          // enabling action bar app icon and behaving it as toggle button
          getSupportActionBar().setDisplayHomeAsUpEnabled(true);
          getSupportActionBar().setHomeButtonEnabled(true);
  
          mTitle = mDrawerTitle = getTitle();
  
          // load slide menu items
          navMenuTitles = getResources().getStringArray(R.array.nav_drawer_items);
  
          // nav drawer icons from resources
          navMenuIcons = getResources()
                  .obtainTypedArray(R.array.nav_drawer_icons);
  
          //mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
          mDrawerLayout= (DrawerLayout) getLayoutInflater().inflate(R.layout.activity_main, null);
          //mDrawerList = (ListView) findViewById(R.id.list_slidermenu);
          mDrawerList = (ListView) mDrawerLayout.findViewById(R.id.list_slidermenu);
  
          navDrawerItems = new ArrayList&lt;NavDrawerItem&gt;();
  
          // adding nav drawer items to array
          // Home
          navDrawerItems.add(new NavDrawerItem(navMenuTitles[0], navMenuIcons.getResourceId(0, -1)));
          // Find People
          navDrawerItems.add(new NavDrawerItem(navMenuTitles[1], navMenuIcons.getResourceId(1, -1)));
          // Photos
          navDrawerItems.add(new NavDrawerItem(navMenuTitles[2], navMenuIcons.getResourceId(2, -1)));
          // Communities, Will add a counter here
          navDrawerItems.add(new NavDrawerItem(navMenuTitles[3], navMenuIcons.getResourceId(3, -1)));
          // Pages
          navDrawerItems.add(new NavDrawerItem(navMenuTitles[4], navMenuIcons.getResourceId(4, -1)));
          // What's hot, We  will add a counter here
          navDrawerItems.add(new NavDrawerItem(navMenuTitles[5], navMenuIcons.getResourceId(5, -1)));
  
  
          // Recycle the typed array
          navMenuIcons.recycle();
  
          mDrawerList.setOnItemClickListener(new SlideMenuClickListener());
  
          // setting the nav drawer list adapter
          adapter = new NavDrawerListAdapter(getApplicationContext(),
                  navDrawerItems);
          mDrawerList.setAdapter(adapter);
  
          mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
                  R.drawable.ic_drawer, //nav menu toggle icon
                  R.string.app_name, // nav drawer open - description for accessibility
                  R.string.app_name // nav drawer close - description for accessibility
          ) {
              public void onDrawerClosed(View view) {
                  getSupportActionBar().setTitle(mTitle);
                  // calling onPrepareOptionsMenu() to show action bar icons
                  invalidateOptionsMenu();
              }
  
              public void onDrawerOpened(View drawerView) {
                  getSupportActionBar().setTitle(mDrawerTitle);
                  // calling onPrepareOptionsMenu() to hide action bar icons
                  invalidateOptionsMenu();
              }
          };
          mDrawerLayout.setDrawerListener(mDrawerToggle);
  
          if (savedInstanceState == null) {
              // on first time display view for first nav item
              displayView(0);
          }
  
      }
  </code></pre>
  
  <p>And finally, i just need to extend the <code>BaseActivity</code> class and code like usual.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>According to the answer, this is my WORKING overrided <code>setContentView</code> :</p>
  
  <pre><code>@Override
      public void setContentView(final int layoutResID) {
          // TODO Auto-generated method stub
          mDrawerLayout= (DrawerLayout) getLayoutInflater().inflate(R.layout.activity_main, null); // Your base layout here
          actContent= (FrameLayout) mDrawerLayout.findViewById(R.id.frame_container);
  
          getLayoutInflater().inflate(layoutResID, actContent, true);
          super.setContentView(mDrawerLayout);
  
          mTitle = mDrawerTitle = getTitle();
  
          // load slide menu items
          navMenuTitles = getResources().getStringArray(R.array.nav_drawer_items);
  
          // nav drawer icons from resources
          navMenuIcons = getResources()
                  .obtainTypedArray(R.array.nav_drawer_icons);
  
          mDrawerList = (ListView) mDrawerLayout.findViewById(R.id.list_slidermenu);
  
          navDrawerItems = new ArrayList&lt;NavDrawerItem&gt;();
  
          // adding nav drawer items to array
          // Home
          navDrawerItems.add(new NavDrawerItem(navMenuTitles[0], navMenuIcons.getResourceId(0, -1)));
          // Find People
          navDrawerItems.add(new NavDrawerItem(navMenuTitles[1], navMenuIcons.getResourceId(1, -1)));
          // Photos
          navDrawerItems.add(new NavDrawerItem(navMenuTitles[2], navMenuIcons.getResourceId(2, -1)));
          // Communities, Will add a counter here
          navDrawerItems.add(new NavDrawerItem(navMenuTitles[3], navMenuIcons.getResourceId(3, -1)));
          // Pages
          navDrawerItems.add(new NavDrawerItem(navMenuTitles[4], navMenuIcons.getResourceId(4, -1)));
          // What's hot, We  will add a counter here
          navDrawerItems.add(new NavDrawerItem(navMenuTitles[5], navMenuIcons.getResourceId(5, -1)));
  
  
          // Recycle the typed array
          navMenuIcons.recycle();
  
          mDrawerList.setOnItemClickListener(new SlideMenuClickListener());
  
          // setting the nav drawer list adapter
          adapter = new NavDrawerListAdapter(getApplicationContext(),
                  navDrawerItems);
          mDrawerList.setAdapter(adapter);
  
          mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
                  R.drawable.ic_drawer, //nav menu toggle icon
                  R.string.app_name, // nav drawer open - description for accessibility
                  R.string.app_name // nav drawer close - description for accessibility
          ) {
              public void onDrawerClosed(View view) {
                  getSupportActionBar().setTitle(mTitle);
                  // calling onPrepareOptionsMenu() to show action bar icons
                  invalidateOptionsMenu();
              }
  
              public void onDrawerOpened(View drawerView) {
                  getSupportActionBar().setTitle(mDrawerTitle);
                  // calling onPrepareOptionsMenu() to hide action bar icons
                  invalidateOptionsMenu();
              }
          };
          mDrawerLayout.setDrawerListener(mDrawerToggle);
  
          //super.setContentView(mDrawerLayout);
          /*getLayoutInflater().inflate(layoutResID, actContent, true);
          super.setContentView(mDrawerLayout);*/
      }
  </code></pre>