Android.app.Fragment inconsistent with android.support.v4.app.Fragment

Source: Internet
Author: User

In the view of the fragment in the type conversion is very easy to see this problem:

Compare code:

Class Myfragmentpageradapter extends Fragmentpageradapter{public myfragmentpageradapter (fragmentmanager FM) {Super ( FM)//Todo auto-generated constructor stub} @Overridepublic Fragment GetItem (int arg0) {//Todo auto-generated method stub Fragment ft = Null;switch (arg0) {case 0:ft = new Mainpaperfragment (); break;default:break;} return ft;} @Overridepublic int GetCount () {//TODO auto-generated method Stubreturn MainActivity.this.tabTitle.length;}}


And:

Import Android.support.v4.app.fragment;import Android.os.bundle;import Android.view.layoutinflater;import Android.view.view;import Android.view.viewgroup;import Com.example.kuhua.r;public class MainPaperFragment extends Fragment {@Overridepublic View oncreateview (layoutinflater inflater, ViewGroup container,bundle savedinstancestate) {/ /TODO auto-generated method Stubview Mainpaperfragmentview = Inflater.inflate (R.layout.mainpaperfragmentview, Container,false); return mainpaperfragmentview;} @Overridepublic void onactivitycreated (Bundle savedinstancestate) {//TODO auto-generated method Stubsuper.onactivitycreated (savedinstancestate);}}

In the above Fragment Fragment ft = new Mainpaperfragment () is not inherently wrong, is a polymorphic, but general development is always prone to error; The reason is, of course, in ourselves, when we use Fragment, we generally know it is imported import Android.support.v4.app.Fragment However, it is easy to use the system import android.app.Fragment when customizing the fragment, which results in inconsistent API usage. The solution is to remember that all the imported import android.support.v4.app.Fragment is OK!

Android.app.Fragment inconsistent with android.support.v4.app.Fragment

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.