I have the following XML for my Activity
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/home_root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<br.com.digitalpages.shelves.view.TopBar
android:layout_width="match_parent"
android:layout_height="60px" />
<LinearLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<fragment
android:id="@+id/fragment_categories"
android:layout_width="240px"
android:layout_height="match_parent"
android:name="br.com.digitalpages.shelves.fragment.TreeCategoryFragment" />
<fragment
android:id="@+id/fragment_library"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:name="br.com.digitalpages.shelves.fragment.LibraryFragment" />
</LinearLayout>
<fragment
android:id="@+id/fragment_bottom_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:name="br.com.digitalpages.shelves.fragment.BottomBarFragment" />
</LinearLayout>
In a click on the Bottom_Bar I need to replace fragment_categories and fragment_library by another Fragment that span the space of the old fragments.
How can I do that?
I tried:
FragmentTransaction trans = getFragmentManager().beginTransaction();
trans.remove(categoryExplorerFragment);
trans.remove(libraryFragment);
trans.add(R.id.fragment_container, new LibraryFragment());
trans.commit();
But when I click, only the libraryFragment disappears and nothing more happens.
use the replace method instead;