Android Practice Note (3)---Fragment use app bag or V4 package parsing

Source: Internet
Author: User

Android Practice Note (3)---Fragment use app bag or V4 package parsing



1) Problem brief

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

watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvy29kzxjfcgln/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/southeast ">

This time the problem comes ...

Is the Android.app under the fragment or the Android.support.v4.app bag under the fragment?



A: Actually all can , yes, can !!! We all know that Fragment was introduced after 3.0 (API one)

So suppose that the app you're developing needs to be executed in the version number below 3.0? for example, another bit of market share of 2.3!

As av4 , the package came into being, and the minimum was compatible with the 1.6 version number !

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; Let's say you fragment with the app pack, Fragmentmanager and fragmenttransaction.

Must be in the app pack.


Either use the Utility app, or the practical V4, otherwise but will be error-Oh!

Of course, if you want your app to be compatible with low-version phones, then you can choose to use the V4 package

But there are a lot of places to pay attention to using V4 bags!



2) Things to note when using the V4 package:


① assumes that you are using the fragment under the V4 package, then the activity that is located is going to inherit fragmentactivity Oh!

Case: In the XML file today statically loaded into the fragment, and then rewrite the fragment, but in the load of activity when the error,

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 's bag, just need to change your activity to fragmentactivity you can do it!



② write this code today when incredibly useless, error conditions such as the following:


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

Activity is also inherited fragmentactivity ah? Change to the app bag, but this is not with US v4 bag

Is the premise in conflict? There's a solution, huh?

Answer: Just need to change getfragmentmanager() to Getsupportfragmentmanager ()




V4 Package fragment Encounter problems temporary on these, later encountered will update the record

Let's say that you can also tell the pig about the problem and the solution, sharing is the virtue of the program Ape! Thank you very much!


Recent updates:


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 still an error message, such as the following:


watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvy29kzxjfcgln/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/southeast ">


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


later asked the next boss, just know is the layout code is wrong, the Add method and replace method after the call object is: ViewGroup (Container) , is the layout;

That means we were wrong in loading the layout file for fragment, so open the layout file:

watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvy29kzxjfcgln/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/southeast ">


It turns out that I used a static method to load the time with a fragment tag, change this to a layout can be, for example, changed to Framelayout

This time the execution is no problem.!fragment is not a container!! ~








Copyright notice: This article Bo Master original article. Blog, not reproduced without consent.

Android Practice Note (3)---Fragment use app bag 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.