title: How to change visibility for MenuItem dynamically?
body: <p>I'm developing some Android application and I have ActionBar with 2 tabs. I need to show 2 icons on ActionBar when user select the second tab. I have the following code:</p>
  
  <pre><code>@Override
  public boolean onCreateOptionsMenu(Menu menu) {
      getMenuInflater().inflate(R.menu.activity_main, menu);
      mOptionsMenu=menu;
      menu.getItem(0).setVisible(false);
      menu.getItem(1).setVisible(false);
      return true;
  } 
  
      public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
          mViewPager.setCurrentItem(tab.getPosition());
          if (tab.getPosition()==1) {
          mOptionsMenu.getItem(0).setVisible(true);
          mOptionsMenu.getItem(1).setVisible(true);
  }
      }
  </code></pre>
  
  <p>But this code doesn't work. Please, tell me, how can I done my needs? </p>