The difference between the use of the fragment in the app Pack and the fragment in the V4 package

Source: Internet
Author: User

The difference between the use of the fragment in the app Pack and the fragment in the V4 package, and the need for a friend to refer to below.

1, try not to use the app package in the fragment, because this is after 3.0, the supported version is too high, in the lower version is not used.

2, Android.support.v4.app.Fragment: can be compatible to 1.6 version.

3, regarding these two fragment to use the label question:
(1), app.fragment and v4.fragment can be used <fragment> tags, Only in the use of the time if it is app.fragment there is no special place, the activity of fragment is normal to inherit the activity class.

(2), when the V4.fragment use the label should pay special attention to:
When the activity is going to use android.support.v4.app.Fragment , the activity must inherit fragmentactivity, or it will get an error:

Caused By:java.lang.ClassCastException:com.example.android_fragment_bottom.fragments.TopBarFragment cannot be cast To Android.app.Fragment

At this point, if you do not inherit Fragmentactivity, the compilation system will treat android.support.v4.app.Fragment as the fragment in the app package. But at this point we are importing the fragment in the V4 package.

An example of fragment in the official Android document is the fragment in the app package.

(3), the application package about the fragment class and methods in the V4 package are corresponding.

(4), the method of obtaining Fragmentmanager is different:

android.app.Fragment: Use the Getfragmentmanager () method.

android.support.v4.app.Fragment: Use the Getsupportfragmentmanager () method.

The difference between the use of the fragment in the app Pack and the fragment in the V4 package

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.