Android Fragment Learning Summary

Source: Internet
Author: User

Common APIs for the Fragment family:


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.FragmenTransaction guarantees the atomicity of some column fragment operations.


1, the way to obtain Fragmentmanager:


Fragmentmanager fm = Getfragmentmanager (); Get Fragmentmanager Object


Fragmenttransaction transacction = Fm.begintransaction (); Open transaction Marks


2, the main operation is in the Fragmenttransaction method


Transaction.add ();//Add a fragment to the activity


Transaction.remove ();//Remove a fragment from activity if the removed fragment is not added to the fallback stack


This fragment instance will be destroyed.


Transaction.replace ();//Replace the current with another fragment, which is actually remove and then in the add


Transaction.hide ();//Hide the current fragment, just set to invisible, and not destroyed.


Transaction.show ();//show previously hidden fragment


Detach ();//will remove the view from the UI, and remove () different, at this time fragment state I still have fragemntmanager maintenance


Attach ();//re-view, attaching to the UI and displaying.


Transaction.commit ();//Commit a transaction


Note: The commit method must be called before Activity.onsavestance ().

Android Fragment Learning Summary

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.