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: androidsmartly

I am a Tech Enthusiast who likes to work on new Ideas. Sharing knowledge on Android, Marketing, Startups and More.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s