要注意的是fragment实际上是有两个版本的,一个是android
import android.support.v4.app.Fragment;app
另一个是继承
import android.app.Fragment;get
这两个版本的fragment是不会兼容的。也就是说要不就全用fragment,要不就全用v4 fragment,不能混搭着用。it
在这里我强烈建议初学者用第二个,也就是简单的fragment,接下来我说说二者的区别你们就知道为何了。io
1.最低支持版本不一样class
android.app.Fragment 兼容的最低版本是android:minSdkVersion="11" 即3.0版import
android.support.v4.app.Fragment 兼容的最低版本是android:minSdkVersion="4" 即1.6版List
2.须要导jar包file
fragment android.support.v4.app.Fragment 须要引入包android-support-v4.jar
3.在Activity中取的方法不一样
android.app.Fragment使用 (ListFragment)getFragmentManager().findFragmentById(R.id.userList) 得到 ,继承Activity(这个仅仅须要继承自最简单的activity)
android.support.v4.app.Fragment使用 (ListFragment)getSupportFragmentManager().findFragmentById(R.id.userList) 得到 ,须要继承android.support.v4.app.FragmentActivity
4.我感受最重要的,是XML标签的使用
android.app.Fragment能够使用<fragment>标签的,这点很重要,若是是用android.support.v4.app.Fragment的话,是不能是用<fragment>标签的,会抛出android.view.InflateException: Binary XML file line #7: Error inflating class fragment异常。
由于这个标签的使用仍是比较简单的,因此仍是比较倾向前者