sirFunkenstine
sirFunkenstine

Reputation: 8495

get Menu outside onOptionsItemSelected

Im looking to set an actionbar menu item visible from a helper class. Is it possible to access the actionbar Menu outside of onOptionsItemSelected through a reference to an activity? code below.

public boolean getMenuFromActivity(BaseActivity activity){
   // something like Menu menu =  activity.getActionBar().getMenu()?
   // then get menu item by id and set visibility..
   //return true if found
   return false
}

Upvotes: 2

Views: 1367

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006584

Simple answer: Call findItem() on the Menu after you have inflated your menu resource in onCreateOptionsMenu(), and hold onto that MenuItem in a data member of your activity, so you can use it later.

Slightly less-simple answer: Hold onto the Menu from onCreateOptionsMenu() in a data member of your activity, and use it later to find your item.

Upvotes: 6

Related Questions