title: Android fragment - different layout into fragment
body: <p>I'm trying to develop an application compatible with smartphones (one pane layout) and tablets (two panes layout). My app is displayed as shown below:</p>
  <p><a href="https://i.stack.imgur.com/82VGb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/82VGb.png" alt="fragment" /></a><br />
  <sub>(source: <a href="http://android10.org/images/stories/develoment_1/working_with_fragments_android10_02.png" rel="nofollow noreferrer">android10.org</a>)</sub></p>
  <p>I used the example available in <a href="https://developer.android.com/guide/components/fragments" rel="nofollow noreferrer">Google developers website</a>.</p>
  <p>The example works fine. But for my app, I need to use different layout in the <code>WebView fragment</code>. Each element selected in <code>ListView fragment</code> shows a specific layout into the right fragment.</p>
  <p>This is my code called when an element is clicked :</p>
  <pre><code>public void onArticleSelected(int position) {
      // The user selected the headline of an article from the
      // HeadlinesFragment
  
      // Capture the article fragment from the activity layout
      BodyFragment articleFrag = (BodyFragment) getSupportFragmentManager().findFragmentById(R.id.body_fragment);
  
      if (articleFrag != null) {
          // If article frag is available, we're in two-pane layout...
  
          // Call a method in the ArticleFragment to update its content
          articleFrag.updateArticleView(position);
  
      } else {
          // If the frag is not available, we're in the one-pane layout and
          // must swap frags...
  
          // Create fragment and give it an argument for the selected
          // article
          BodyFragment newFragment = new BodyFragment();
  
          Bundle args = new Bundle();
          args.putInt(BodyFragment.ARG_POSITION, position);
          newFragment.setArguments(args);
          FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
  
          // Replace whatever is in the fragment_container view with this
          // fragment,
          // and add the transaction to the back stack so the user can
          // navigate back
          transaction.replace(R.id.fragment_container, newFragment);
          transaction.addToBackStack(null);
  
          // Commit the transaction
          transaction.commit();
      }
  }
  </code></pre>
  <p>How can I should make it? I thought to replace dynamically the layout into the fragment, but it is not possible.</p>
  <p>Is anybody has a solution?</p>
  <p>thanks in advance</p>