title: How can I open a Fragment under the open NavigationDrawer with defining the Drawer in a separate fragment?
body: <p>My app opens the NavigationDrawer at start. 
  When the user clicks on any item in it a Fragment is being replaced.</p>
  
  <p>For every item in my navigation drawer I have a separate Fragment. 
  BUT when the user does not choose any of the options in the NavigationDrawer and CLOSES it,
  the main activit layout is being shown. </p>
  
  <p>I want one of my own fragments to be brought up when the user closes the side menu. (navigation drawer)
  But I get a NPE when I try to change</p>
  
  <pre><code>setContentView(R.layout.activity_main);
  </code></pre>
  
  <p>with </p>
  
  <pre><code>setContentView(R.layout.my_fragment);
  </code></pre>
  
  <p>(Because it cannot find navigation_drawer since it is defined in activity_main)</p>
  
  <p>I don't like to put my NavigationDrawer in one of my fragments, neither do I like to copy my fragment elements to my main.xml (it will be a messy design :( ).
   What am I supposed to do?
  How am I supposed to open my desired fragment underneath the NavigationDrawer??</p>
  
  <p>here is my onCreate in MainActivity:</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      mNavigationDrawerFragment = (FragmentNavigationDrawer) getSupportFragmentManager().findFragmentById(R.id.navigation_drawer);
      mNavigationDrawerFragment.setUp(R.id.navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout));
      mTitle = getTitle();
  }
  </code></pre>
  
  <p>here is my activity_main.xml</p>
  
  <pre><code>&lt;!-- A DrawerLayout is intended to be used as the top-level content view using match_parent for both width and height to consume the full space available. --&gt;
  </code></pre>
  
  <p></p>
  
  <pre><code>&lt;!--
       As the main content view, the view below consumes the entire
       space available using match_parent in both dimensions.
  --&gt;
  
  &lt;FrameLayout
      android:id="@+id/container"
      android:layout_width="match_parent"
      android:layout_height="match_parent" /&gt;
  
  &lt;!--
       android:layout_gravity="start" tells DrawerLayout to treat
       this as a sliding drawer on the left side for left-to-right
       languages and on the right side for right-to-left languages.
       If you're not building against API 17 or higher, use
       android:layout_gravity="left" instead.
  --&gt;
  &lt;!--
       The drawer is given a fixed width in dp and extends the full height of
       the container.
  --&gt;
  
  &lt;fragment
      android:id="@+id/navigation_drawer"
      android:name="com.khoonat.khoonat.FragmentNavigationDrawer"
      android:layout_width="@dimen/navigation_drawer_width"
      android:layout_height="match_parent"
      android:layout_gravity="start"
      tools:layout="@layout/fragment_navigation_drawer" /&gt;
  </code></pre>
  
  <p></p>
  
  <p>Is this a bad solution? 
  please note that I'm kind of a beginner :)</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      FragmentManager fragmentManager = getSupportFragmentManager();
      fragmentManager.beginTransaction().replace(R.id.container, FragmentSearchPropertyListing.newInstance(0)).commit();
  
      mNavigationDrawerFragment = (FragmentNavigationDrawer) getSupportFragmentManager().findFragmentById(R.id.navigation_drawer);
      mNavigationDrawerFragment.setUp(R.id.navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout));
      mTitle = getTitle();
  }
  </code></pre>
  
  <p>The red arrow shows what I mean by under the navigation drawer.
  <img src="https://i.stack.imgur.com/SOVlK.png" alt="enter image description here"></p>