Recently all in the company to test, static heart to learn Android. Let's get fragment today.
Several points of fragment:
1. For large-screen tablets, accommodating more components, reusable 2.Fragment must be embedded in the activity
3.Fragment has its own life cycle, but must be in the state where activity is run (after all, embedded in activity)
Fragment Inheritance System:
Fragment callback method:
OnCreate (): callback When creating fragment object
Oncreateview (): Callback when drawing component, returns a view, as shown in fragment
OnPause (): Callback When you leave
Suppose the present scenario is: Fragment A contains a news list, Fragment B contains news content, the user taps the news list on the left side of the screen, and the right side of the screen lists the appropriate content.
How it works: The Activity a layout file defines listfragment A, and an empty framelayout (used to be replaced);
News list content is provided by listfragment A;
The user clicks on the news list, the first response is listfragment A, and then by listfragment a value to Acitivity a,activity a received value, replace framelayout to fragment B, through fragment b setargument (Bundle) method to fragment B value, and finally in Fragemtn B to get the value, to be processed.
Directly to the crazy Android handout second version of the source code to see it.
Android: Understanding Fragment