title: Fragments within Fragments
body: <p>I'm wondering if this is actually a bug in the Android API:</p>
  
  <p>I have a setup like so:</p>
  
  <pre><code>┌----┬---------┐
  |    |         |
  |  1 |    2    |
  |    |┌-------┐|
  |    ||       ||
  |    ||   3   ||
  └----┴┴-------┴┘
  </code></pre>
  
  <ol>
  <li>Is a menu which loads fragment #2 (A search screen) in the right pane.</li>
  <li>Is a search screen which contains fragment #3, which is a result list.</li>
  <li>The result list is used in several places (including as a functioning high level fragment in it's own right).</li>
  </ol>
  
  <p>This functionality works perfectly well on a phone (Where 1 &amp; 2 and 3 are <code>ActivityFragment</code>s). </p>
  
  <p>However, when I used this code:</p>
  
  <pre><code>    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();       
      Fragment frag = new FragmentNumber2();
      if(toLoad != null) frag.setArguments(toLoad);
      transaction.replace(R.id.rightPane, frag);      
      transaction.commit();
  </code></pre>
  
  <p>Where <code>R.id.leftPane</code> and <code>R.id.rightPane</code> are <code>&lt;fragment&gt;</code>s in a horizontal linear layout.</p>
  
  <p>It is my understanding that the above code removes the fragment which is resident and then replaces it with a new fragment. Brilliant... Obviously that isn't what happens because when this code runs the second time you get the following exception:</p>
  
  <pre><code>07-27 15:22:55.940: ERROR/AndroidRuntime(8105): Caused by: java.lang.IllegalArgumentException: Binary XML file line #57: Duplicate id 0x7f080024, tag null, or parent id 0x0 with another fragment for FragmentNumber3
  </code></pre>
  
  <p>This is caused because the the container for FragmentNumber3 has been duplicated and it no longer has a unique ID. The initial Fragment hasn't been destroyed (?) before the new one is added (in my mind that means it hasn't been <em>replaced</em>).</p>
  
  <p>Can someone tell me if this is possible (<a href="https://stackoverflow.com/questions/5268361/fragments-in-action-bar-tab-fragments/5280000#5280000">this answer</a> suggests it isn't) or is it a bug?</p>