My Android app has a requirement where a certain flow has 7 different screens. Now each of these screens has a common top and bottom. So i have chosen to create a FragmentActivity
and 7 different Fragments
. How do I insert the fragments into the FragmentActivity
at runtime? I have read this tutorial here, and according to this tutorial my main FragmentActivity
should have the following layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<FrameLayout
android:id="@+id/fragment_content"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
And it should use the following code to replace the fragment:
FragmentManager fm = getSupportFragmentManager();
Fragment fragment = fm.findFragmentById(R.id.fragment_content);
if (fragment == null) {
FragmentTransaction ft = fm.beginTransaction();
ft.add(R.id.fragment_content, new BasicFragment());
ft.commit();
}
What I don't understand is the following line:
ft.add(R.id.fragment_content, new BasicFragment());
R.id.fragment_content
is a FrameLayout
, will this insert the fragment into the FrameLayout
or what?