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.

Author: Ankur

I am Enthusiastic about Learning new things and sharing my Knowledge. I like programming and have a pretty good background in Computer Science.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: