java - FragmentPagerAdapter android.support.v4.app.fragment can not be applied to android.ap.Fragment -


first of all, found hundred of question on topic , solution none of them me. because m doing little different workaround.

fragmentpageradapter class constructor

import android.support.v4.app.fragment; import android.support.v4.app.fragmentmanager;  public class homepage_slider extends fragmentpageradapter {     public homepage_slider(fragmentmanager fragmentmanager) {         super(fragmentmanager);         myarr.addall(globalvariable.slider_image_url);         mcount =myarr.size();     }      public homepage_slider(android.app.fragmentmanager fragmentmanager) {         super(fragmentmanager);     }  } 

fragment class

import android.app.fragment;  public class host extends fragment {        public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) {         rootview = inflater.inflate(r.layout.content_navigation_drawer, container, false);          top_slider = rootview.findviewbyid(r.id.home_slider_image);         viewpager = (viewpager) top_slider.findviewbyid(r.id.pager);         viewpager.setadapter(new homepage_slider(getactivity().getfragmentmanager()));         }  } 

i using navigation drawer using support library , follow tutorial navigation drawer tutorial . , trying use fragmentpageradapter display slider. , host fragment class uses import android.app.fragment; , fragmentpageradapter class uses import android.support.v4.app.fragment;

because of host fragment class not import import android.support.v4.app.fragment;
fragmentpageradapter constructor giving error fragmentpageradapter android.support.v4.app.fragment can not applied android.ap.fragment

while searching solution found changing import trick rest app stop working. used import android.app.fragment; other work calling other fragment class transaction

//host fragment have code  swap next fragment on click event on listview  ((mainactivity)getactivity()).category_product_page();    // class contains    mainactivity.java   // go wishlist page     public void category_product_page() {         // create new fragment , transaction         cart_product newfragment = new cart_product ();         fragmenttransaction transaction = getfragmentmanager().begintransaction();         // replace whatever in fragment_container view fragment,         // , add transaction stack         transaction.replace(r.id.frame_container, newfragment);         transaction.addtobackstack(null);         // commit transaction         transaction.commit();     } 

and did other work on host fragment that's why can not change import android.app.fragment " import android.support.v4.app.fragment; suggestion helpful.

please suggest how can overcome error , prevent these error in future second app have slider

fragmentpageradapter android.support.v4.app.fragment can not applied android.ap.fragment

when using android.support.v4.app.fragmentmanager should use getsupportfragmentmanager() , if using android.app.fragmentmanager call getfragmentmanager()

you using import android.support.v4.app.fragment;

don't

    viewpager.setadapter(new homepage_slider(getactivity().getfragmentmanager()));     fragmenttransaction transaction = getfragmentmanager().begintransaction(); 

do

     viewpager.setadapter(new homepage_slider(getactivity().getsupportfragmentmanager()));      fragmenttransaction transaction = getsupportfragmentmanager().begintransaction(); 

you should call getsupportfragmentmanager () instead of getfragmentmanager() .

return fragmentmanager interacting fragments associated activity.


Comments