Sehran Hasanli
Sehran Hasanli

Reputation: 41

Input for onPrepareOptionsMenu

I'm trying to make an app that disables the user from going to the menu. I know I have to override onPrepareOptionsMenu(Menu menu) but what do I have to put as input for menu if I want to use this function in a different function? I don't quite understand the Menu object and how many types it has.

Upvotes: 0

Views: 37

Answers (1)

Panayiotis Irakleous
Panayiotis Irakleous

Reputation: 2696

Do something like this:

private Menu mOptionsMenu;

@Override
public boolean onCreateOptionsMenu(final Menu menu) {
    mOptionsMenu = menu
    ...
}

private void updateOptionsMenu() {
    if (mOptionsMenu != null) {
        onPrepareOptionsMenu(mOptionsMenu);
    }
}

and then call the updateOptionsMenu() function where you want

Upvotes: 1

Related Questions