Android Basics – Learn about the FragmentManager and how to use it in an Activity

Now that you have created an Activity and a Fragment chances are that your Activity needs to talk to the Fragment.

Like your Activity may need to send the Fragment some data, say List ID. And using this ID the Fragment will display details.

To refer to a Fragment you cannot use the findViewById method.

In order to reference a Fragment in an Activity we use FragmentManager.

  • Step 1   Use getFragmentManager() which is available in your Activity class to get a reference to FragmentManager.
  • Step 2   Use getFragmentManager().findFragmentById() to get reference to the Fragment you need to use.

Follow the Video to learn more. You can view the Source Code here.