This repository was archived by the owner on Jul 9, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Instantiating FragmentController
bkolarov-appolica edited this page Apr 10, 2017
·
8 revisions
FragmentController is actually a fragment that does all the magic. So as a fragment, it needs a container.
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
To instantiate the controller, you must use the FragmentController#instance(FragmentProvider)
method. This method accepts a FragmentProvider that represents the root fragment. Root fragment - that is the first fragment that will be shown when you add the controller to FragmentManager.
See more about FragmentProvider.
Suppose you're in activity:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
final FragmentController controller = FragmentController.instance(rootFragment);
getSupportFragmentManager().beginTransaction()
.replace(R.id.container, controller, CONTROLLER_TAG)
.commit();
....
Or if you're in a fragment:
@Override
public void onViewCreated(final View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
...
final FragmentController controller = FragmentController.instance(rootFragment);
getChildFragmentManager().beginTransaction()
.replace(R.id.container, controller, CONTROLLER_TAG)
.commit();
...