title: How can I implement FragmentManager and FragmentTransaction to replace just a single fragment?
body: <p>I have an activity with 3 fragments; a header; a body; a footer (same point as in HTML). The bodyfragment contains three buttons which each should replace the middle fragment (body; itself) with another one, but I can't figure out how to work FragmentManager and FragmentTransition in here. I can't seem to find any coherency in other peoples questions on here with regards to the way others implement their fragments. It seems everyone has their own methods, or just doesn't include the full code in their threads.</p>
  
  <p>MainActivity.java</p>
  
  <pre><code>public class MainActivity extends Activity {
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      this.requestWindowFeature(Window.FEATURE_NO_TITLE);
      this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
      setContentView(R.layout.test_frag);
  }
  
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.main, menu);
      return true;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>TestFragment.java</p>
  
  <pre><code>public class TestFragment extends Fragment {
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState) {
  
      return inflater.inflate(R.layout.test_frag, container, false);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>BodyFragment.java</p>
  
  <pre><code>public class BodyFragment extends Fragment {
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState) {
  
      return inflater.inflate(R.layout.body_frag, container, false);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Fragment in XML</p>
  
  <pre><code>&lt;fragment
      android:id="@+id/bodyfragment"
      android:name="com.example.test.BodyFragment"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:layout_weight="1"
      tools:layout="@layout/body_frag" /&gt;
  </code></pre>
  
  <p>BodyFragment layout in XML (button x3)</p>
  
  <pre><code>    &lt;Button
      android:id="@+id/bsettings"
      android:layout_width="130dp"
      android:layout_height="40dp"
      android:layout_alignBaseline="@+id/bgames"
      android:layout_alignBottom="@+id/bgames"
      android:layout_toRightOf="@+id/bgames"
      android:text="SETTINGS" /&gt;
  </code></pre>