Monday, 15 February 2010

android - Incompatible types: Fragment cannot be converted to NavigationDrawerFragment -



android - Incompatible types: Fragment cannot be converted to NavigationDrawerFragment -

i've been working on app using api 14, had downgrade api 10. app has fragments , activity fragments, have imported libraries , used getfragmentsupportmanager because v4. however, have next error:

i created dummy app drawer layout , fragments api 10 beginning, had same line in myactivity file , not error. here code:

package az.test2; import android.app.activity; import android.os.bundle; import android.view.layoutinflater; import android.view.menu; import android.view.menuitem; import android.view.view; import android.view.viewgroup; import android.support.v4.widget.drawerlayout; import android.support.v7.app.actionbaractivity; import android.support.v7.app.actionbar; import android.support.v4.app.fragment; import android.support.v4.app.fragmentmanager; import android.view.gravity; public class myactivity extends actionbaractivity implements navigationdrawerfragment.navigationdrawercallbacks { /** * fragment managing behaviors, interactions , presentation of navigation drawer. */ private navigationdrawerfragment mnavigationdrawerfragment; /** * used store lastly screen title. utilize in {@link #restoreactionbar()}. */ private charsequence mtitle; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_my); mnavigationdrawerfragment = (navigationdrawerfragment) getsupportfragmentmanager().findfragmentbyid(r.id.navigation_drawer); mtitle = gettitle(); // set drawer. mnavigationdrawerfragment.setup( r.id.navigation_drawer, (drawerlayout) findviewbyid(r.id.drawer_layout)); } @override public void onnavigationdraweritemselected(int position) { // update main content replacing fragments android.support.v4.app.fragmentmanager lolo; fragmentmanager fm = getsupportfragmentmanager(); fragav fav = new fragav(); fragw fw = new fragw(); switch (position){ case 0: fm.begintransaction() .replace(r.id.container, fav).commit(); break; case 1: fm.begintransaction() .replace(r.id.container, fw).commit(); break; case 2: break; } //fm.begintransaction().replace(r.id.container, placeholderfragment.newinstance(position + 1)).commit(); } public void onsectionattached(int number) { switch (number) { case 1: mtitle = getstring(r.string.title_section1); break; case 2: mtitle = getstring(r.string.title_section2); break; case 3: mtitle = getstring(r.string.title_section3); break; } } public void restoreactionbar() { actionbar actionbar = getsupportactionbar(); actionbar.setnavigationmode(actionbar.navigation_mode_standard); actionbar.setdisplayshowtitleenabled(true); actionbar.settitle(mtitle); } @override public boolean oncreateoptionsmenu(menu menu) { if (!mnavigationdrawerfragment.isdraweropen()) { // show items in action bar relevant screen // if drawer not showing. otherwise, allow drawer // decide show in action bar. getmenuinflater().inflate(r.menu.my, menu); restoreactionbar(); homecoming true; } homecoming super.oncreateoptionsmenu(menu); } @override public boolean onoptionsitemselected(menuitem item) { // handle action bar item clicks here. action bar // automatically handle clicks on home/up button, long // specify parent activity in androidmanifest.xml. int id = item.getitemid(); if (id == r.id.action_settings) { homecoming true; } homecoming super.onoptionsitemselected(item); } /** * placeholder fragment containing simple view. */ public static class placeholderfragment extends fragment { /** * fragment argument representing section number * fragment. */ private static final string arg_section_number = "section_number"; /** * returns new instance of fragment given section * number. */ public static placeholderfragment newinstance(int sectionnumber) { placeholderfragment fragment = new placeholderfragment(); bundle args = new bundle(); args.putint(arg_section_number, sectionnumber); fragment.setarguments(args); homecoming fragment; } public placeholderfragment() { } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view rootview = inflater.inflate(r.layout.fragment_my, container, false); homecoming rootview; } @override public void onattach(activity activity) { super.onattach(activity); ((myactivity) activity).onsectionattached( getarguments().getint(arg_section_number)); } } }

i did error seems rare. help much appreciated.

when using back upwards pack, fragments should extend android.support.v4.app.fragment , not regular fragment class.

android android-fragments drawerlayout

No comments:

Post a Comment