About fragment API version number compatibility issues

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.