java - Option Menu won't display -
i want show menu action bar, menu won't display, source code :
public class epolicymainactivity extends tabactivity { /** called when activity first created. */ public void oncreate(bundle savedinstancestate) { //hide title bar basicdisplaysettings.toggletaskbar(epolicymainactivity.this, false); //show status bar basicdisplaysettings.togglestatusbar(epolicymainactivity.this, true); super.oncreate(savedinstancestate); setcontentview(r.layout.menu); resources res = getresources(); // resource object drawables tabhost tabhost = gettabhost(); // activity tabhost tabhost.tabspec spec; // resusable tabspec each tab intent intent; // reusable intent each tab // create intent launch activity tab (to reused) intent = new intent().setclass(this, loginactivity.class); spec = tabhost.newtabspec("login").setindicator("", res.getdrawable(r.drawable.epolicy_menu_xml_home)) .setcontent(intent); tabhost.addtab(spec); intent = new intent().setclass(this, nabactivity.class); spec = tabhost.newtabspec("nab").setindicator("", res.getdrawable(r.drawable.epolicy_menu_xml_nab)) .setcontent(intent); tabhost.addtab(spec); intent = new intent().setclass(this, contactactivity.class); spec = tabhost.newtabspec("contact").setindicator("", res.getdrawable(r.drawable.epolicy_menu_xml_contact)) .setcontent(intent); tabhost.addtab(spec); intent = new intent().setclass(this, agenactivity.class); spec = tabhost.newtabspec("agen").setindicator("", res.getdrawable(r.drawable.epolicy_menu_xml_agen)) .setcontent(intent); tabhost.addtab(spec); (int = 0; < tabhost.gettabwidget().getchildcount(); i++){ tabhost.gettabwidget().getchildat(i).setpadding(0,0,0,0); tabhost.gettabwidget().getchildtabviewat(i).setbackgrounddrawable(null); } tabhost.setcurrenttab(0); } public boolean oncreateoptionsmenu(menu menu) { menuinflater inflater = getmenuinflater(); inflater.inflate(r.menu.menu, menu); return super.oncreateoptionsmenu(menu); } public boolean onoptionsitemselected(menuitem item) { super.onoptionsitemselected(item); switch (item.getitemid()) { case r.id.menu_bantuan: intent itabout = new intent(epolicymainactivity.this, epolicybantuan.class); itabout.addflags(intent.flag_activity_new_task); startactivity(itabout); break; case r.id.menu_exit: dialogexit(); break; case r.id.menu_logout: dialogsignout(); break; } return true; } public void dialogsignout() { alertdialog.builder builder = new alertdialog.builder(this); builder.setmessage("apakah anda ingin sign-out?") .setcancelable(false) .setpositivebutton("ya", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int id) { intent itsignout = new intent(epolicymainactivity.this, loginactivity.class); itsignout.addflags(intent.flag_activity_new_task); startactivity(itsignout); finish(); } }) .setnegativebutton("tidak", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int id) { dialog.cancel(); } }); alertdialog alert = builder.create(); alert.show(); } public void dialogexit() { alertdialog.builder builder = new alertdialog.builder(this); builder.setmessage("apakah anda ingin keluar?") .setcancelable(false) .setpositivebutton("ya", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int id) { intent itsplashend = new intent(epolicymainactivity.this, splashoutactivity.class); itsplashend.addflags(intent.flag_activity_clear_top); itsplashend.addflags(intent.flag_activity_new_task); startactivity(itsplashend); finish(); } }) .setnegativebutton("tidak", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int id) { dialog.cancel(); } }); alertdialog alert = builder.create(); alert.show(); } @override public void onbackpressed() { dialogexit(); }
this menu.xml :
<menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/menu_bantuan" android:title="@string/menu_bantuan" android:orderincategory="100" android:showasaction="ifroom|withtext"/> <item android:id="@+id/menu_exit" android:title="@string/menu_exit" android:orderincategory="100" android:showasaction="ifroom|withtext" /> <item android:id="@+id/menu_logout" android:title="@string/menu_logout" android:orderincategory="100" android:showasaction="ifroom|withtext" />
in main layout, i'm using header, giving effect menu, menu won't display or else?
i under assumption should first call super.
public boolean oncreateoptionsmenu(menu menu) { super.oncreateoptionsmenu(menu); menuinflater inflater = getmenuinflater(); inflater.inflate(r.menu.menu, menu); return true; }
i assuming menu.xml has appropriate menu closing tag. have xml file stored in res/menu folder? can verify oncreateoptionsmenu called?
on android 2.3 , lower have press menu button, whereas in later distributions should displayed in title bar. since using tabactivity assume writing app android 2.3.
this question might useful onmenuitemselected() method: merge tabactivity menu contained activities menus
for activities within tabactivity: how create optionsmenu in android's tabactivity
perhaps when press menu button, options menu of specific tab activity in (e.g. loginactivity) called, , not of parent. try putting code in every subactivity:
public boolean oncreateoptionsmenu(menu menu) { return getparent().oncreateoptionsmenu(menu); }
Comments
Post a Comment