title: Android - Changing the contentview of the activity of Navigation drawer
body: <p>I am creating a simple QR scanning app using Navigation drawer to go throw different fragments, for the QR scanning part I am using the ZXing Scanner library.</p>
  
  <p>In one of the fragments, there is a button called "scan", When clicked the following code run</p>
  
  <pre><code>mScannerView = new ZXingScannerView(this);
  setContentView(mScannerView); // HERE IS THE begining OF THE PROBLEM
  mScannerView.setResultHandler(this);
  mScannerView.startCamera();
  </code></pre>
  
  <p>now in the <code>handleResult</code> method i should write the following code to close the camera.</p>
  
  <pre><code>mScannerView.stopCamera();
  setContentView(R.layout.activity_main); // THE PROBLEM OCCUERS HERE
  </code></pre>
  
  <p>When I run this code I get <code>Binary XML file line #36: Binary XML file line #36: Error inflating class fragment</code></p>
  
  <p>Any Idea how to solve this ?</p>
  
  <p>Code :</p>
  
  <p>Main Activity:</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity implements FragmentDrawer
      .FragmentDrawerListener, ZXingScannerView.ResultHandler {
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      drawerFragment = (FragmentDrawer) getSupportFragmentManager().findFragmentById(R.id.fragment_navigation_drawer);
      drawerFragment.setUp(R.id.fragment_navigation_drawer, (DrawerLayout) findViewById(R.id
              .drawer_layout), mToolbar);
      drawerFragment.setDrawerListener(this);
  
      displayView(0);
  }
  
  @Override
  public void onDrawerItemSelected(View view, int position) {
      displayView(position);
  }
  
  private void displayView(int position) {
      Fragment fragment = null;
      switch (position) {
          case 0:
              fragment = new QRScanerFragment();
              title = getString(R.string.title_logout);
              break;
          default:
              break;
      }
  
      if (fragment != null) {
          FragmentManager fragmentManager = getSupportFragmentManager();
          FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
          fragmentTransaction.replace(R.id.container_body, fragment);
          fragmentTransaction.commit();
      }
  }
  
  public void scan(View view) {
      mScannerView = new ZXingScannerView(this);
      setContentView(mScannerView);
      mScannerView.setResultHandler(this);
      mScannerView.startCamera();
  }
  
  @Override
  public void handleResult(Result result) {
      Log.e("QR result", result.getText());
      mScannerView.stopCamera();
      setContentView(R.layout.activity_main);
  }
  
  @Override
  protected void onPause() {
      super.onPause();
      mScannerView.stopCamera();
  }
  </code></pre>
  
  <p>}</p>
  
  <p>as For the XML:</p>
  
  <pre><code>&lt;android.support.v4.widget.DrawerLayout
  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"&gt;
  
  
  &lt;LinearLayout
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical"&gt;
  
      &lt;FrameLayout
          android:id="@+id/container_body"
          android:layout_width="fill_parent"
          android:layout_height="0dp"
          android:layout_weight="1" /&gt;
  
  
  &lt;/LinearLayout&gt;
  
  
  &lt;fragment
      android:id="@+id/fragment_navigation_drawer"
      android:name="com.bassiouny.androidqrtask.fragments.FragmentDrawer"
      android:layout_width="@dimen/nav_drawer_width"
      android:layout_height="match_parent"
      android:layout_gravity="start"
      app:layout="@layout/fragment_navigation_drawer"
      tools:layout="@layout/fragment_navigation_drawer" /&gt;
  </code></pre>
  
  <p></p>