android - How to get an MenuItem by id -


i have menuitem on res/menu/student_marks.xml file:

<menu xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     tools:context=".studentmarks" >     <item android:id="@+id/action_selected_year"         android:title="@string/action_selected_year"         android:showasaction="withtext|ifroom"         style="@style/apptheme" /> </menu> 

now need item set title.in specific part of app.

can work specific item in method:

onoptionsitemselected(menuitem item) 

the problem need item 'action_selected_year' without of method in part of program.
don't have idea how it.

menu optionsmenu;      @override     public boolean oncreateoptionsmenu(menu menu) {        getmenuinflater().inflate(r.menu.main, menu);        //  store menu var when creating options menu        optionsmenu = menu;     } 

example: change icon on first menuitem (optionsmenu should != null)

optionsmenu.getitem(0).seticon(getresources()     .getdrawable(r.drawable.ic_action_green)); 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -