android - How to edit the list in the right up corner that contains settings? -


i tried

    @override     public boolean oncreateoptionsmenu(menu menu) {         log.v(                 this.getclass().getname() + "!!!",                  new exception().getstacktrace()[0].getmethodname()                 );         menuitem m_item = (menuitem)menu.finditem(r.id.action_settings);         if(m_item != null)             m_item.settitle("back test");         // inflate menu; adds items action bar if present.         getmenuinflater().inflate(r.menu.settings, menu);         return true;     } 

but gets null.and also,oncreate seems have null well. there function can modify text on during runtime??? , if so, there easy way find it?right corner, want change text on "settings" during runtime

you should add items in menu xml. can find on folder res/menu. there have menus available inflation.

i suppose have one. how added options:

<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto">  <item     android:id="@+id/searchmain"         android:icon="@drawable/ic_action_search"     app:showasaction="ifroom|withtext"     android:title="search"/> <item     android:id="@+id/searchbarcodescan"     android:icon="@drawable/ic_launcher"     app:showasaction="always|withtext"     android:title="scanner"/> <item     android:id="@+id/seelist"     android:icon="@drawable/ic_launcher"     app:showasaction="ifroom|withtext"     android:title="see list"/> <item     android:id="@+id/settings"     android:icon="@drawable/ic_settings"     app:showasaction="ifroom|withtext"     android:title="settings"/> </menu> 

then in activity can react option selected overriding method , doing things inside it:

@override public boolean onoptionsitemselected(menuitem item) {     switch (item.getitemid()) {      case r.id.searchmain:         dosomething();         return true;      case r.id.searchbarcodescan:         dosomething2();         return true;      case r.id.seelist:         dosomething3();         return true;      case r.id.settings:         dosomething4();         return true;     }     return super.onoptionsitemselected(item); }        

edit in order change menus in runtime, should call method invalidateoptionsmenu(). method force recreation of menu , time onprepareoptionsmenu method called. should override in activity way:

@override public boolean onprepareoptionsmenu(menu menu) {     if(somecondition){         getmenuinflater().inflate(r.menu.main_menu, menu);     }     else if(someothercondition){         getmenuinflater().inflate(r.menu.other_menu, menu);     }     return true; } 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -