clamp
clamp

Reputation: 34036

android: different menu depending on situation

hello i would like to present a different menu in my activity depending on some condition. i tried like this.

@Override
public boolean onCreateOptionsMenu(Menu menu)
{
    MenuInflater inflater = getMenuInflater();
    if (specialMode)
    {
        inflater.inflate(R.menu.menuA, menu);
    }
    else
    {
        inflater.inflate(R.menu.menuB, menu);
    }
    return true;
}

however, i always get the same menu, no matter what the value of specialMode is.

Upvotes: 1

Views: 552

Answers (1)

Nikolay Ivanov
Nikolay Ivanov

Reputation: 8935

onCreateOptionsMenu is called only once ( upon first creation), try using onPrepareOptionsMenu method it get called every time menu is shown.

Upvotes: 4

Related Questions