Fragment was introduced in API one (Android 3.0). However, my app's android:minisdkversion is API 8, which means the app is compatible with the old version number. In order to be compatible with the older version number, you need to introduce fragment related support packages
Import android.support.v4.app.Fragment;
Instead of a local package
Import android.app.Fragment;
Although both the Android support package and the local package contain fragment related classes, these classes that are distributed in two packages are not interoperable.
Fragmentmanager FM =getsupportfragmentmanager (); Fragment Fragment = Fm.findfragmentbyid (R.id.fragmentcontainer); if (fragment==null) {fragment = new crimefragment (); Fm.begintransaction (). Add (r.id.fragmentcontainer,fragment). Commit ();
In This code, the packages we import are these:
Import android.support.v4.app.Fragment;
Import android.support.v4.app.FragmentActivity;
Import Android.support.v4.app.FragmentManager;
Instead of these:
Import Androidapp. Fragment;
Import Androidapp. fragmentactivity;
Import Android.app.FragmentManager;
If you import a local package, you will get an error.
About fragment API version number compatibility issues