Justin Lazarus
Justin Lazarus

Reputation: 107

Android access menu from onOptionsItemSelected

I have the following in my activity (sorry new to Java/Android):

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.options, menu);
    return super.onCreateOptionsMenu(menu);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId()) {
    case R.id.selectItem:
            // menu.add(...) --> how to get the menu instance?
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

I am wondering, how can I access a menu object in onOptionsItemSelected? For example, how would I go about adding a new view to the options menu based on the selection of an existing menu item? Is the answer related to "onPrepareOptionsMenu"?

Upvotes: 1

Views: 4789

Answers (1)

Selvin
Selvin

Reputation: 6797

you should use SubMenu for such things ... remeber that you cant add submenu to another submenu ... so only Menu->Submenu is possible you can't do stuff like this Menu->Submenu->Submenu (while Submenu is Dialog with choices)

Upvotes: 1

Related Questions