Ok, cada vez que trato de reemplazar un fragmento en mi aplicación, solo agrega el fragmento dentro del contenedor del otro fragmento y deja el fragmento actual. Intenté llamar a reemplazar y hacer referencia a la vista que contiene el fragmento, y haciendo referencia al fragmento en sí. Ninguno de estos funciona. Puedo agregar un fragmento a una vista con el administrador de transacciones de fragmento, pero incluso si trato de eliminarlo después de que se ha agregado, no funciona. Cualquier ayuda sería apreciada. Aquí están mis archivos.Duplicación de fragmentos en Fragment Transaction
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//Setup the actionabar. Use setDrawableBackground to set a background image for the actionbar.
final ActionBar actionbar = getActionBar();
actionbar.setDisplayShowTitleEnabled(false);
actionbar.setDisplayUseLogoEnabled(true);
actionbar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionbar.addTab(actionbar.newTab().setText(R.string.home_tab_text).setTabListener(this),true);
actionbar.addTab(actionbar.newTab().setText(R.string.insert_tab_text).setTabListener(this));
Fragment fragment = new insert_button_frag();
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(R.id.button_fragment, fragment);
transaction.addToBackStack(null);
transaction.commit();
}
Este es el diagrama
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:id="@+id/button_fragment_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<fragment
android:name="com.bv.silveredittab.home_button_frag"
android:id="@+id/button_fragment"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<fragment
android:name="com.bv.silveredittab.quick_insert_frag"
android:id="@+id/quick_insert_frag"
android:layout_width="350dip"
android:layout_height="fill_parent" />
<fragment
android:name="com.bv.silveredittab.editor_frag"
android:id="@+id/editor_frag"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
</LinearLayout>
Y aquí es el código de fragmento
public class insert_button_frag extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
return inflater.inflate(R.layout.insert_buttons,container, false);
}
}
Como he dicho. He intentado hacer referencia a la vista primaria de fragmentos para reemplazarla, y el fragmento mismo (por id) y aún así, solo agrega el nuevo fragmento, dentro de la vista que contiene el fragmento original.
¿Qué hay en el archivo de diseño insert_buttons.xml? – Peter