![]() ![]() First, we can get the FragmentManger using the Activity method getFragmentManager(). We are more interested in some other methods.Īll the operation that are made by the FragmentManager happens inside a “transaction” like in a database operation. A tag in a fragment is simply a “name” we give to the fragment so that we can find it later using that name. While the first method is very simple and we use the common android id to discover the component, the second method (that uses tag) is unsual. Using FragmentManager we can discover ( find) fragment inside our layout using findFragmentById or findFragmentByTag. ![]() So now we have all the freedom to “inject” in the FrameLayout our fragments.Īs we said before FragmentManager is the key component. ![]() This component can add, replace and remove fragments at runtime. With FrameLayout we can handle fragments as we need at runtime, but to do it we need a manager, in other words a component that can handle fragments. So if we want to make our layout dynamic (and this happen very often) we need to do it in another way. In this case our layout isn’t dynamic because we can’t manage the fragment at runtime. ![]() Static method is when we “write” directly our fragment in XML file. In Android there are two different methods to create fragment: With transaction we mean a sequence of steps to add, replace or remove fragments. In the last post we showed how to support multiple screen size and orientation using fragments. To manage fragments we need a FragmentManager that help us to handle trasaction between fragments. Fragments are useful when we want to support multiple screen size. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |