Only the hands are the ape, only the mind is the design corpse, I want to become the program corpse
Understanding: First, we know that fragment is that we need to switch multiple UI interfaces on a single activity to display different content. These UI panels are modularized to facilitate the use of other acitifiers. At the same time, the fragment we show will also be affected by the current acitivity lifecycle. (The usual fragment has its own lifecycle)
I. Usage:
1. Create one or more fragment classes that you need. They are similar to activity and have callback functions such as oncreate.
2. If you want to use fragment for the current program, that is, activity, you need to move the relevant callback function content in acitivity. You might simply move code from your activity's callback methods into the respective callback Methods
Of your fragment
Generally, we need the following callback function:
Oncreate ()
Oncreateview ()
Onpause ()
In addition to the above three callback function methods that we basically need, we have written other: handling in fragment.
The fragment Lifecycle
Ii. Inheritance of the fragment class
In addition to the basic fragment class, we can also inherit the following:
Dialogfragment
Listfragment
Preferencefragment
3. Add User Interface
Let's try againonCreateView()It processes the interface to be displayed for our fragment, and returns a view. This view is actually the root item (the outermost and largest) of layout of this fragment !).
We use the layoutinflater helper class to generate a view from the XML layout.