FragmentActivity和Activity的區別



FragmentActivity is a special activity provided in the Support Library to handle fragments on system versions older than API level 11. If the lowest system version you support is API level 11 or higher, then you can use a regular Activity.

意思是:FragmentActivityAPI11之前的版本,你的類要繼承FragmentActivity用來處理3.0之後出現的Fragment(對應包含頭文件 import android.support.v4.app.Fragment),其FragmentManager獲取方法是:getSupportFragmentManager(),3.0以後的版本繼承Activity就行,用getFragmentManager()獲取,這樣你就能在Activity中嵌入Fragment了。


教程起因:

       在用ViewPager的時候用到其setAdapter( FragmentManager fm)函數,首先我用的V4包,繼承的是Activity,提示錯誤:The constructor MyFragmentAdapter(FragmentManager, List<Fragment>) is undefined


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章