title: Android: Showing Action Bar menu items depending on ViewPager
body: <p>I am having trouble getting the following piece of code to work out.  I have a <code>viewpager</code> with 3 fragments, and I want a search icon to only show up on one.  I started off trying to add the search function by the fragment, but the rendering of the menu item was slow when swiping to that page.  I am now on the part to add the search icon to the activity, and then just hide or show depending on which <code>viewpager</code> page is active, but the following is not working:</p>
  
  <pre><code>public class MyApp extends FragmentActivity implements 
     FragmentTeams.FragmentNotification,ViewPager.OnPageChangeListener, 
        OnNavigationListener{
  
    ...
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      getMenuInflater().inflate(R.menu.activity_main, menu);
  
      menuSearch = menu.findItem(R.id.menu_search);
      mSearchView = new SearchView(this);
      menuSearch.setActionView(mSearchView);
      menuSearch.setVisible(false);
      return true;
  }
  
   @Override
  public void onPageSelected(int pageNum) {
  
  if(pageNum== 1){     
      ActionBar actionBar = MyApp.this.getActionBar();
          actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);     
          menuSearch.setVisible(true);
          invalidateOptionsMenu();
  
  }else{           
      ActionBar actionBar = MyApp.this.getActionBar();
          actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);  
          menuSearch.setVisible(false);
          invalidateOptionsMenu();
      }
  }
  </code></pre>
  
  <p>While the above does (appear to) create and hide the icon at <code>onCreateOptionsMenu</code>, it is not reenabled when moving to</p>
  
  <pre><code> pageNum ==1  
  </code></pre>
  
  <p>Can anyone give me some insight as to why this may be happening?</p>