Is there a convenient way to display the same options menu options in multiple actions?
Example. In my application, I show the TV Guide in one of three ways.
- Seven-Day Reference (7-Tab TabActivity)
- All Show Channels (ListActivity)
- Everything shows today by start time (Activity - can easily be changed to ListActivity)
In the Options menu in TabActivity code is pretty simple ...
@Override public boolean onPrepareOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); menu.clear(); inflater.inflate(R.menu.gv_options_menu, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.view: ... ... } }
... but at the moment it seems to me that I need to copy / paste it into the other two actions that I don't like. If I changed the code for the Options menu for one, I would need to do this for the other two as well.
The only alternative I can come up with is a “helper class” (POJO), to which I could add a method, and pass context inside to allow the use of the getMenuInflator() method and another method that I could pass the result of item.getItemId() for processing using the patch case.
What is the normal way to have multiple activities with the same options menu?
source share