java - Editing the ActionBar with a FragmentActivity that implements ActionBar.TabListener -



java - Editing the ActionBar with a FragmentActivity that implements ActionBar.TabListener -

in android app, trying add together icons actionbar in fragmentactivity; however, remains blank.

i want actionbar have 2 icons block.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" tools:context=".setupactivity" > <item android:id="@+id/action_overflow" android:title="@string/action_settings" android:orderincategory="100" android:icon="@drawable/ic_action_overflow" app:showasaction="always" /> <item android:id="@+id/action_search" android:title="@string/search" android:orderincategory="200" android:icon="@drawable/ic_action_search" app:showasaction="always" /> </menu>

i trying follow this: oncreateoptionsmenu not beingness called on fragmentactivity when run on phone version

here blockactivity class extends fragmentactivity. unsure why actionbar unable edited in spite of having oncreateoptionsmenu method.

package com.spicycurryman.getdisciplined10.app; import android.annotation.targetapi; import android.app.fragmenttransaction; import android.os.build; import android.os.bundle; import android.app.actionbar; import android.support.v4.app.fragmentactivity; import android.support.v4.view.viewpager; import android.view.menu; import android.view.menuinflater; import info.androidhive.tabsswipe.adapter.tabspageradapter; // /** * created spicycurryman on 6/17/14. */ public class blockactivity extends fragmentactivity implements actionbar.tablistener { private viewpager viewpager; private tabspageradapter madapter; private actionbar actionbar; // tab titles private string[] tabs = {"installed", "system", "custom"}; @targetapi(build.version_codes.ice_cream_sandwich) @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.block_apps); // initilization viewpager = (viewpager) findviewbyid(r.id.pager); actionbar = getactionbar(); madapter = new tabspageradapter(getsupportfragmentmanager()); viewpager.setadapter(madapter); actionbar.sethomebuttonenabled(false); actionbar.setnavigationmode(actionbar.navigation_mode_tabs); // adding tabs (string tab_name : tabs) { actionbar.addtab(actionbar.newtab().settext(tab_name) .settablistener(this)); } /** * on swiping viewpager create respective tab selected * */ viewpager.setonpagechangelistener(new viewpager.onpagechangelistener() { @override public void onpageselected(int position) { // on changing page // create respected tab selected actionbar.setselectednavigationitem(position); } @override public void onpagescrolled(int arg0, float arg1, int arg2) { } @override public void onpagescrollstatechanged(int arg0) { } }); } //here oncreateoptionsmenu method should work public boolean oncreateoptionsmenu(menu menu){ menuinflater inflater = getmenuinflater(); inflater.inflate(r.menu.block, menu); homecoming true; } @override public void ontabselected(actionbar.tab tab, fragmenttransaction fragmenttransaction) { viewpager.setcurrentitem(tab.getposition()); } @override public void ontabunselected(actionbar.tab tab, fragmenttransaction fragmenttransaction) { } @override public void ontabreselected(actionbar.tab tab, fragmenttransaction fragmenttransaction) { } }

should oncreateoptionsmenu implemented in separate fragments?

you did not phone call super.oncreateoptionsmenu(menu); within oncreateoptionsmenu method thats why remains blank.

solution:

public boolean oncreateoptionsmenu(menu menu){ menuinflater inflater = getmenuinflater(); inflater.inflate(r.menu.block, menu); homecoming super.oncreateoptionsmenu(menu); }

add well:

@override public boolean onprepareoptionsmenu(menu menu) { homecoming super.onprepareoptionsmenu(menu); }

add action well:

@override public boolean onoptionsitemselected(menuitem item) { int id = item.getitemid(); if (id == r.id.action_overflow) { homecoming true; } else if(id == r.id.action_search) { homecoming true; } homecoming super.onoptionsitemselected(item); }

java android xml android-fragments android-actionbar

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -