Michel Feinstein
Michel Feinstein

Reputation: 14266

Android Fragment management

I am learning Android Apps development and in this guide, the API makes it clear a Fragment can be managed in at runtime, so far you have the fragment's id or tag.

But this tutorial in the other hand says you can only deal with fragments at runtime IF you don't declare them in the XML.

I find this very confusing...Which one is right?

Upvotes: 0

Views: 124

Answers (1)

ILovemyPoncho
ILovemyPoncho

Reputation: 2792

If you declare a fragment in a XML layout with the <fragment> tag, you cannot replace it dinamically at runtime.

If you declare in xml layout a container(FrameLayout) for different fragments. Using FragmentTansaction you will be able to add a fragment to that container and then replace it or remove it at runtime. As you will see in the Building a Flexible UI lesson:

In order to replace one fragment with another, the activity's layout includes an empty FrameLayout that acts as the fragment container.

Upvotes: 1

Related Questions