Some of the error Android.app.FragmentManager and Android.support.v4.app.FragmentManager bring

Source: Internet
Author: User

A fragment is a part or a behavior in the interface of an activity. You can combine multiple fragment into one activity to create a faceted interface and you can reuse a fragment in multiple activity. You can think of fragment as a modular activity that has its own life cycle and receives its own events. And can be added or deleted when the activity is executed.

A good post: http://my.oschina.net/u/270164/blog/85347.

        Use fragment package as Android.app.FragmentManager , But because it is incompatible with version number 3.0, introduce android.support.v4.app.fragmentmanager  Two packages the same definition of fragment is different, so in import, often easy confusion causes the program to error. The following is summed up below:

1, compile error-free, execution times wrong: android.view.InflateException:Binary XML file line #7: Error inflating class fragment

The above error occurs because you have used the <fragment> tag in an. xml file, but the corresponding Xx.java file is android.support.v4.app.Fragment. android.support.v4.app.Fragment: Can be compatible to 1.6 version number, cannot use <fragment> tag, need to add in the program or replace the way to join.

2. Compile Error:

import Android.os.Bundle ; import android.support.v4.app.FragmentActivity ; import Android.support.v4.app.FragmentManager ; import android.support.v4.app.FragmentTransaction ; public class Mainactivity extends fragmentactivity { public static Fragmentmanager CHILDFM; protected void OnCreate (Bundle savedinstancestate) { super. OnCreate (savedinstancestate); Setcontentview (r.layout. Activity_main);CHILDFM =getsupportfragmentmanager (); fragmenttransaction ft= childfm. BeginTransaction (); Frag1 f1= New Frag1 (); Ft. Add (F1, "first"). commit ();     }}

code as above. Prompt at add: the method Add (Fragment, String) in Thetype fragmenttransaction are not applicable for the arguments (Frag1, String).

Cause: In my frag1.java. Import packet is android.app.Fragment so error.

Change to import android.support.v4.app.Fragment; just fine.

3, in addition, when the activity is called, the package is android.support.v4.app.FragmentActivity class, all extends is fragmentactivity instead of activity.



Some of the error Android.app.FragmentManager and Android.support.v4.app.FragmentManager bring

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.