title: Fragment doesn't replace and hide another fragment
body: <p>I'm working on an android project and my fragment are not working...</p>
  
  <p>I'm trying to have this kind of UI ->
  <a href="http://developer.android.com/training/basics/fragments/fragment-ui.html" rel="nofollow">http://developer.android.com/training/basics/fragments/fragment-ui.html</a></p>
  
  <p>However my second fragment doesn't replace or hide the first one, it's simply going under it!</p>
  
  <p>This is how I declare my first fragment in the main activity:</p>
  
  <pre><code>setContentView(R.layout.finallayout);
      Bundle bundle = new Bundle();
      bundle.putStringArrayList("urllist", URLlist);
      // set Fragmentclass Arguments
      MainFragment main = new MainFragment();
      main.setArguments(bundle);
      getFragmentManager().beginTransaction().add(R.id.scrollcontentcontainer, main,"list").commit();
  </code></pre>
  
  <p>In the onCreateView of this one, I'm adding some content: </p>
  
  <pre><code>mainview = inflater.inflate(R.layout.finallayout, container, false);
      scollviewgroup= (ViewGroup) container.findViewById(R.id.scrollcontentcontainer);
      //mainview.setOnClickListener(this);
  
      for (int i = 0; i &lt; json.size(); i++) {
          lineartab.add(inflater.inflate(R.layout.relativeaqi, scollviewgroup, false));
          createMainLayout(this.json.get(i), i, lineartab.get(i), scollviewgroup, inflater);
  
      }
  </code></pre>
  
  <p>and that's the way I declare the second one:</p>
  
  <pre><code> Fragment contentFragment = new CoreFragment();
                  FragmentManager fm = getActivity().getFragmentManager();
                  FragmentTransaction fragmentTransaction = fm.beginTransaction();
                 // fragmentTransaction.add(contentFragment, "core");
                  fragmentTransaction.replace(R.id.scrollcontentcontainer, contentFragment);
                  fragmentTransaction.addToBackStack(null);
                  fragmentTransaction.commit();
  </code></pre>
  
  <p>On the onCreateView, I'm inflating with a layout contained in a other layout file:</p>
  
  <pre><code>    @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  
      //container.removeAllViews();
      //IF I USE THIS ONE I HAVE THE EXPECTED RESULT, HOWEVER I M NOT SURE THATS THE BEST WAY TO DO IT SINCE ITS REMOVING THE CONTENT INCLUDED IN THE OTHER FRAGMENT
  
  
      View view = inflater.inflate(R.layout.placecore, container, false);
  
      return view;
  }
  </code></pre>
  
  <p>Trying to use add instead of  replace, or using hide doesn't work.</p>
  
  <p>I want my two fragments to use the same layout template, but with an unique instance of it for each fragment, I don't know if it's possible or not. I tried to use a different layout file for the second one but then I had always an error saying <code>No view found for id...</code></p>
  
  <p>Anyone know how to fix that? thanks</p>
  
  <p>xml files:
  finallayout.xml</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/mainlayout"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"&gt;
  
  &lt;RelativeLayout
      android:id="@+id/bottomcontent"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:layout_alignParentBottom="true"
      android:focusable="false"&gt;
  
  &lt;/RelativeLayout&gt;
  
  
  
      &lt;LinearLayout
          android:id="@+id/scrollcontentcontainer"
          android:focusable="false"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:orientation="vertical"&gt;
  
      &lt;/LinearLayout&gt;
  </code></pre>
  
  <p></p>
  
  <p>and placecore.xml, which contains the content of the 2nd fragment.
  It contains many textviews and buttons I hide to make it more clear(i put "some content" instead):</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/corecontainer"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:gravity="center"
  android:orientation="vertical"
  android:paddingTop="20dp"
  android:clickable="true"&gt;
  
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/alayout"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:gravity="center"
      android:orientation="vertical"&gt;
  
      some content
  
  &lt;/LinearLayout&gt;
  
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/wlayout"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:layout_marginLeft="20dp"
      android:layout_marginRight="20dp"
      android:background="#1d010101"
      android:orientation="horizontal"
      android:paddingBottom="20dp"
      android:paddingLeft="20dp"
      android:paddingRight="20dp"
      android:paddingTop="20dp"&gt;
  
      some content
  
  
  &lt;/LinearLayout&gt;
  
  
  
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/playout"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:gravity="center"
      android:orientation="vertical"&gt;
  
      some content
  
      &lt;/LinearLayout&gt;
  
  
  &lt;/LinearLayout&gt;
  </code></pre>