The study of Fragmet

Source: Internet
Author: User

Fragment was added after 3.0, because the tablet screen is too large, an activity first is too monotonous, this time there is a fragment.

Look at its life cycle first, because the life cycle of fragment is dependent on activity.

Fragment commonly used in three classes:

Android.app.Fragment is primarily used to define Fragment

Android.app.FragmentManager is primarily used to operate in activity fragment

Android.app.FragmentTransaction to ensure that some of the column fragment operation of the atom, familiar with the word business, you will understand ~

A, the way to obtain Fragmentmanage:

Getfragmentmanager ()//V4, Getsupportfragmentmanager

b, the main operation is the method of Fragmenttransaction

Fragmenttransaction transaction = Fm.bengintransatcion ();//Open a transaction

Transaction.add ()

Add a fragment to the activity

Transaction.remove ()

Remove a fragment from the activity, if the removed fragment is not added to the fallback stack (which is detailed later in the fallback stack), the fragment instance will be destroyed.

Transaction.replace ()

Replace the current with another fragment, which is actually the fit of remove () and then add () ~

Transaction.hide ()

Hides the current fragment, is only set to invisible, and does not destroy

Transaction.show ()

Show previously hidden fragment

Detach ()

The view is removed from the UI, unlike remove (), where the state of the fragment is maintained by Fragmentmanager.

Attach ()

Rebuilds the view view, attaches to the UI, and displays.

Transatcion.commit ()//Commit a transaction

The study of Fragmet

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.