Fragment of V4

Source: Internet
Author: User

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.

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.