B. Money
B. Money

Reputation: 931

Why isn't MenuInflater Responding?

I am a noob to android and i am trying to inflate two different menus depending on user selection. However, the menu isn't switching. The same menu inflates everytime regardless of what the user selects. I've tried and checked my if/else statmente with various parameters and the menu inflater still doesn't respond properly by only inflating the same menu. Any help is greatly appreciated.

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    // TODO Auto-generated method stub
    super.onCreateOptionsMenu(menu);
    popUpMenu = getMenuInflater();
    //popUpMenu.inflate(R.menu.cool_menu, menu);
    if(mypodcast==null){
        popUpMenu.inflate(R.menu.cool_menu, menu);
    }else  {
        popUpMenu.inflate(R.menu.podcast, menu);
    }
    return true;
}

Upvotes: 0

Views: 88

Answers (1)

Sam
Sam

Reputation: 86948

The same menu inflates everytime regardless of what the user selects.

That is because onCreateOptionsMenu() is not called each time you open the menu, from the documentation:

This is only called once, the first time the options menu is displayed. To update the menu every time it is displayed, see onPrepareOptionsMenu(Menu)

If you want to change menus you need to do this in onPrepareOptionsMenu(). However I don't believe that you can or should inflate a new menu every time onPrepareOptionsMenu() is called. But you can combine the two menus and change the visibility of each menu item according to what you want in this method.

Upvotes: 1

Related Questions