Fragment with app package or V4 package parsing

Source: Internet
Author: User

Transferred from: http://blog.csdn.net/zc0908/article/details/50721553

1) Problem Brief

Believe that a lot of friends in the call fragment will encounter the following situation:

This time the problem comes ...

In the end is to use Android.app under the fragment or Android.support.v4.app bag under the fragment?

Answer: Actually all can, yes, can all!!! We all know that fragment was introduced after 3.0 (API 11).

So what if the app needs to run in a version under 3.0? For example, there is a little bit of market share of 2.3!

As a V4, the package has come into being, and the minimum is compatible to version 1.6!

As to which package to use to see your needs, now 3.0 of the mobile phone market share is actually not much, along the street are

More than 4.0, so this time, you can directly use the app package under the fragment, and then call the relevant method

usually there is no problem; If you fragment use the app pack, Fragmentmanager and Fragmenttransaction

It needs to be an app package.

Either use all the app, or all with V4, otherwise it will be an error Oh!

Of course if you want your app to be compatible with the lower version of the phone, then you can choose to use the V4 package

But use V4 pack a lot to pay attention to place!

2) Things to note when using the V4 package:

① If you use the fragment under the V4 package, then the activity will inherit fragmentactivity Oh!

Case: The fragment is loaded statically in the XML file today, and then the fragment is rewritten, but when the activity is loaded, an error is made.

Probably the hint is fragment error or can not find what, the Name property changed several times or wrong! I finally found out it was used.

V4 of the bag, just let your own activity to change to Fragmentactivity can!

② write this code today when it is not used, the error situation is as follows:

A little baffling ah, fragment,fragmentmanager,fragmenttransaction are used V4 bag Ah,

Activity is also inherited fragmentactivity ah? Change to the app bag, but it's not with US V4 bag.

Does the premise conflict? There is a solution, huh?

A: Just change the Getfragmentmanager () to Getsupportfragmentmanager ().

V4 Package fragment encountered problems for the time being, later encountered will update the record

If you can also put the problems encountered and solutions to tell Piglet, sharing is the virtues of programmers Oh!

Last Updated:

2014.11.14 today meets a very funny problem ha, is about dynamic loading fragment

Package all with the V4 package, fragment also inherited Fragmentactivity, get Fragmentmanager also used

Getsuppotfragmentmanager, but the error message is as follows:

Obviously changed the Ah, and the code is not wrong Ah,

Later asked the next eldest brother, just know is the layout code is wrong, add method and replace method call after the object is: ViewGroup (container), is the layout;

It's just that we're loading the fragment layout file wrong, so, open the layout file:

The original is the static method used to load the time with a fragment tag, change this to a layout can be, such as change to Framelayout

It's no problem running at this time!fragment is not a container!! ~

Fragment with app package or V4 package parsing

Related Article

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.