In the developers’s guide, it’s said that a Fragment can be added programmatically at run time to an existing ViewGroup. My question is : how is this ViewGroup linked to the application?
So far, I have tried to declare a ViewGroup in the xml files describing the layout of my application. But when I try to add a Fragment to it by using the public abstract FragmentTransaction add (int containerViewId, Fragment fragment, String tag) function, my application crashes (not immediatly but at the end of the onCreate function of my application).
What I actually want to do is manage several views (implemented as Fragment) in my application and to switch between them according to the user’s choices. What should I add (or change) in my approach?
Thanks in advance for the time you will spend trying to help me.
ViewGroup can be simple frame layout
Then for replace this frame with you fragment you need do nex:
You can hide or show fragments in transaction with command: