Android: Understanding Fragment

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.