Tuesday, 15 March 2011

java - Error: The constructor MainActivity.ScreenSlidePagerAdapter(FragmentManager) is undefined -



java - Error: The constructor MainActivity.ScreenSlidePagerAdapter(FragmentManager) is undefined -

i tried implement android project in http://developer.android.com/training/animation/screen-slide.html , have error in 1 class

import android.os.bundle; import android.annotation.suppresslint; import android.app.activity; import android.app.fragment; import android.app.fragmentmanager; import android.content.intent; import android.support.v4.app.fragmentactivity; import android.support.v4.app.fragmentstatepageradapter; import android.support.v4.app.navutils; import android.support.v4.view.pageradapter; import android.support.v4.view.viewpager; import android.view.layoutinflater; import android.view.menu; import android.view.menuitem; import android.view.view; import android.view.viewgroup; import android.widget.button; public class mainactivity extends fragmentactivity { private static final int num_pages = 5; private viewpager mpager; private pageradapter mpageradapter; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); mpager = (viewpager) findviewbyid(r.id.pager); mpageradapter = new screenslidepageradapter(getfragmentmanager()); mpager.setadapter(mpageradapter); mpager.setonpagechangelistener(new viewpager.simpleonpagechangelistener() { @override public void onpageselected(int position) { // when changing pages, reset action bar actions since dependent // on page active. alternative approach have each // fragment expose actions (rather activity exposing actions), // simplicity, activity provides actions in sample. invalidateoptionsmenu(); } }); } @suppresslint("newapi") @override public boolean oncreateoptionsmenu(menu menu) { super.oncreateoptionsmenu(menu); getmenuinflater().inflate(r.menu.activity_main, menu); menu.finditem(r.id.action_previous).setenabled(mpager.getcurrentitem() > 0); // add together either "next" or "finish" button action bar, depending on page // selected. menuitem item = menu.add(menu.none, r.id.action_next, menu.none, (mpager.getcurrentitem() == mpageradapter.getcount() - 1) ? r.string.action_finish : r.string.action_next); item.setshowasaction(menuitem.show_as_action_if_room | menuitem.show_as_action_with_text); homecoming true; } @override public boolean onoptionsitemselected(menuitem item) { switch (item.getitemid()) { case android.r.id.home: // navigate "up" demo construction launchpad activity. // see http://developer.android.com/design/patterns/navigation.html more. navutils.navigateupto(this, new intent(this, mainactivity.class)); homecoming true; case r.id.action_previous: // go previous step in wizard. if there no previous step, // setcurrentitem nothing. mpager.setcurrentitem(mpager.getcurrentitem() - 1); homecoming true; case r.id.action_next: // advance next step in wizard. if there no next step, setcurrentitem // nothing. mpager.setcurrentitem(mpager.getcurrentitem() + 1); homecoming true; } homecoming super.onoptionsitemselected(item); } private class screenslidepageradapter extends fragmentstatepageradapter { public screenslidepageradapter(fragmentmanager fm) { super(fm); } public fragment getitem(int position) { homecoming screenslidepagefragment.create(position); } public int getcount() { homecoming num_pages; } } }

i building project in android 4.2.

edit:i have changed code into

private class screenslidepageradapter extends fragmentstatepageradapter { public screenslidepageradapter(android.support.v4.app.fragmentmanager fm) { super(fm); }

and

@override public android.support.v4.app.fragment getitem(int position) { homecoming firstframe.create(position); }

then there error occuring in

mpageradapter = new screenslidepageradapter(getfragmentmanager());

error :the constructor mainactivity.screenslidepageradapter(fragmentmanager) undefined

instead of this:

mpageradapter = new screenslidepageradapter(getfragmentmanager());

do this:

mpageradapter = new screenslidepageradapter(getsupportfragmentmanager());

because

getfragmentmanager() goes import android.app.fragmentmanager

and

getsupportfragmentmanager() goes android.support.v4.app.fragmentmanager

java android android-viewpager

No comments:

Post a Comment