android eclipse how to use intent to show the second window in default navigation drawer -
so guys new in android programming , have no background in java.
my problem : code possible?
this default navigation drawer project code, added code intent when run app "unfortunately app has stopped" on switch case 1. im trying when user clicked section1 drawer window section 1 show.
sorry newbie here.
package com.example.example; public class mainactivity extends activity implements navigationdrawerfragment.navigationdrawercallbacks { /** * fragment managing behaviors, interactions , presentation of * navigation drawer. */ private navigationdrawerfragment mnavigationdrawerfragment; /** * used store last screen title. use in * {@link #restoreactionbar()}. */ private charsequence mtitle; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); mnavigationdrawerfragment = (navigationdrawerfragment) getfragmentmanager().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 fragmentmanager fragmentmanager = getfragmentmanager(); fragmentmanager.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); intent intent = new intent(mainactivity.this, navigationdrawerfragment.class); startactivity(intent); break; case 2: mtitle = getstring(r.string.title_section2); break; case 3: mtitle = getstring(r.string.title_section3); break; } } public void restoreactionbar() { actionbar actionbar = getactionbar(); 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, let drawer // decide show in action bar. getmenuinflater().inflate(r.menu.main, menu); restoreactionbar(); return true; } return 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) { return true; } return 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); return fragment; } public placeholderfragment() { } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view rootview = inflater.inflate(r.layout.fragment_main, container, false); return rootview; } @override public void onattach(activity activity) { super.onattach(activity); ((mainactivity) activity).onsectionattached(getarguments().getint(arg_section_number)); } } }
when starting second activity need use class name of activity in intent.
intent intent = new intent(mainactivity.this, navigationdrawerfragment.class);
i cannot see have created navigationdrawerfragment
class.
this why not responding.
Comments
Post a Comment