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) is undefined


你可能感兴趣的:(FragmentActivity和Activity的区别)