title: using layout file for fragment in Navigation drawer layout
body: <p>I have an android app code that uses the navigation drawer layout with fragments as the main content. 
  So far I have had a specific fragment class for all the fragment items in my drawer. Now I do however have a different layout I want to get as an item in my drawer as well. The layout is a LiniarLayout and defined in xml characteristic.xml</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_margin="10dp"&gt;
      &lt;LinearLayout android:orientation="horizontal"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_margin="10dp"&gt;
          &lt;TextView android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="@string/label_device_address"
              android:textSize="18sp"/&gt;
          &lt;Space android:layout_width="5dp"
              android:layout_height="wrap_content"/&gt;
          &lt;TextView android:id="@+id/device_address"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:textSize="18sp"/&gt;
       &lt;/LinearLayout&gt;
       &lt;LinearLayout android:orientation="horizontal"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_margin="10dp"&gt;
          &lt;TextView android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="@string/label_state"
              android:textSize="18sp"/&gt;
          &lt;Space android:layout_width="5dp"
              android:layout_height="wrap_content"/&gt;
          &lt;TextView android:id="@+id/connection_state"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:text="@string/disconnected"
              android:textSize="18sp"/&gt;
      &lt;/LinearLayout&gt;
      &lt;LinearLayout android:orientation="horizontal"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_margin="10dp"&gt;
          &lt;TextView android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="@string/label_data"
              android:textSize="18sp"/&gt;
          &lt;Space android:layout_width="5dp"
              android:layout_height="wrap_content"/&gt;
          &lt;TextView android:id="@+id/data_value"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:text="@string/no_data"
             android:textSize="18sp"/&gt;
      &lt;/LinearLayout&gt;
     &lt;ExpandableListView android:id="@+id/gatt_services_list"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"/&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>in my main activity I preload the fragments in the onCreate</p>
  
  <pre><code> @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          //create adapters early
          mAdapter = new DeviceAdapter(this, false);
  
          mFilterAdapter = new DeviceAdapter(this, true);
          setContentView(R.layout.activity_main);
          mFragmentManager = getFragmentManager();
          mNavigationDrawerFragment = (NavigationDrawerFragment)
                  mFragmentManager.findFragmentById(R.id.navigation_drawer);
          mTitle = getTitle();
  
          // Set up the drawer.
          mNavigationDrawerFragment.setUp(
                  R.id.navigation_drawer,
                  (DrawerLayout) findViewById(R.id.drawer_layout));
  
          mDevices = new HashMap&lt;String, ScanResultContent.BtLeDeviceItem&gt;();
          mFilteredDevices = new HashMap&lt;String, ScanResultContent.BtLeDeviceItem&gt;();
          //setup fragment 1
          mScanResultFragment = new ResultListFragment();
          //setup fragment 2
          mFilteredScanResultFragment = new ResultListFragment();
          mScanResultFragment.setListAdapter(mAdapter);
          //setup fragment 3
          mDeviceInfoFragment = DeviceInfoFragment.newInstance("");
  
          // Sets up UI references for the Device Info viewer.
          mConnectionState = (TextView) findViewById(R.id.connection_state);
          mDataField = (TextView) findViewById(R.id.data_value);
          mGattServicesList = (ExpandableListView) findViewById(R.id.gatt_services_list);
          mGattServicesList.setOnChildClickListener(servicesListClickListner);
  
          mFilteredScanResultFragment.setListAdapter(mFilterAdapter);
          // setup default fragment shown
          mFragmentManager.beginTransaction().add(R.id.container, mScanResultFragment).commit();
      }
  </code></pre>
  
  <p>I have tried to get the layout loaded into a fragment using the DeviceInfoFragment class:</p>
  
  <pre><code>public class DeviceInfoFragment extends Fragment {
  
      public DeviceInfoFragment(){
          super();
      }
  
      public static DeviceInfoFragment newInstance(String text) {
  
          DeviceInfoFragment f = new DeviceInfoFragment();
  
          Bundle b = new Bundle();
          b.putString("text", text);
          f.setArguments(b);
          return f;
      }
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
          View v =  inflater.inflate(R.layout.gatt_characteristics_layout, container, false);    
          return v;
      }
  }
  </code></pre>
  
  <p>I want to be able to switch between the fragments using this (which have worked fine except for the new fragment 3):</p>
  
  <pre><code>@Override
  public void onNavigationDrawerItemSelected(int position) {
      // update the main content by replacing fragments
      Fragment f = null;
      switch (position+1){
          case 1:
              f = mScanResultFragment;
              mTitle = getString(R.string.title_devicescan);
              break;
          case 2:
              f = mFilteredScanResultFragment;
              mTitle = getString(R.string.title_results);
              break;
          case 3:
              f = mDeviceInfoFragment;
              mTitle = getString(R.string.title_device_info);
              break;
      }
      if(f != null) {
          mFragmentManager.beginTransaction()
                  .replace(R.id.container, f)
                  .commit();
      }
      restoreActionBar();
  }
  </code></pre>
  
  <p>It does however not seem to work as the line: 
              mGattServicesList.setOnChildClickListener(servicesListClickListner);
  fails with 
      E/AndroidRuntime(30644): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ExpandableListView.setOnChildClickListener(android.widget.ExpandableListView$OnChildClickListener)' on a null object reference</p>
  
  <p>Can anyone tell me what I am doing wrong here? </p>