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