¿Cómo puedo implementar FragmentManager y FragmentTransaction para reemplazar un solo fragmento?
Tengo una actividad con 3 fragmentos; un encabezado un cuerpo; un pie de página (mismo punto que en HTML). El fragmento de cuerpo contiene tres botones, cada uno de los cuales debe reemplazar el fragmento medio (cuerpo; sí mismo) con otro, pero no puedo averiguar cómo funciona FragmentManager y FragmentTransition aquí. Parece que no puedo encontrar ninguna coherencia en las preguntas de otras personas aquí con respecto a la forma en que otros implementan sus fragmentos. Parece que cada uno tiene sus propios métodos, o simplemente no incluye el código completo en sus hilos.
MainActivity.java
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;
}
}
TestFragment.java
public class TestFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.test_frag, container, false);
}
}
BodyFragment.java
public class BodyFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.body_frag, container, false);
}
}
Fragmento en XML
<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" />
Diseño de BodyFragment en XML (botón x3)
<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" />