Fragment之一:基本原理
1、低版本API對Fragment的支持
Fragment必須被加載進Acitivity中,才能呈現。而在低于3.0版本的API中,由于不存在Fragment,因此必須使用support包:
(1)對于1.6(API=4)及以上版本:
?創建Fragment時,應該繼承android.support.v4.app.Fragment;
?創建Activity時,應該繼承android.support.v4.app.FragmentActivity;
(2)對于2.1(API=7)及以上版本:(為同時支撐ActionBar)
創建Fragment時,應該繼承android.support.v4.app.Fragment;(這個還需要確認一下)
創建Activity時,應該繼承android.support.v7.app.ActionBarActivity
(3)他們之間的關系為:
java.lang.Object
? ?? android.content.Context
? ? ? android.content.ContextWrapper
? ? ?android.view.ContextThemeWrapper
? ? ?android.app.Activity
? ? ?android.support.v4.app.FragmentActivity
? ? ?android.support.v7.app.ActionBarActivity
2、addToBackStack()
Keep in mind that when you perform fragment transactions, such as replace or remove one, it's often appropriate to allow the user to navigate backward and "undo" the change. To allow the user to navigate backward through the fragment transactions, you must call addToBackStack() before you commit the FragmentTransaction.
3、Fragment之間的通信
To allow a Fragment to communicate up to its Activity, you can define an interface in the Fragment class and implement it within the Activity.
總結
以上是生活随笔為你收集整理的Fragment之一:基本原理的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Loader之二:CursorLoade
- 下一篇: AdapterView及其子类之一:基本