title: How do I remove a menu item on the fly?
body: <p>My Android app has a navigation drawer with a menu.  In the free version of the app, I want to have a menu item to allow the user to Upgrade to the paid version.  Obviously I don't want this in the paid version.</p>
  
  <p>How do I hide the menu item in the paid version?</p>
  
  <p>The menu looks like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;menu
      xmlns:android="http://schemas.android.com/apk/res/android"&gt;
  
     &lt;item
          android:id="@+id/action_home"
          android:icon="@drawable/btn_home"
          android:title="@string/nav_home"
          /&gt;
      &lt;item
          android:id="@+id/action_acc_upgrade"
          android:icon="@drawable/ic_star_black"
          android:title="@string/str_acc_upgrade" /&gt;
      &lt;item
          android:id="@+id/action_help"
          android:icon="@drawable/ic_help_black"
          android:title="@string/nav_help"
          /&gt;
  &lt;/menu&gt;
  </code></pre>
  
  <p>In the activity, I have:</p>
  
  <pre><code>@Override
  public boolean onCreateOptionsMenu(Menu menu) {
      super.onCreateOptionsMenu(menu);
  
      MenuInflater inflater = this.getMenuInflater();
      inflater.inflate(R.menu.activity_main_drawer, menu);
  
      if(isPaid()) {
          MenuItem upgrade = menu.findItem(R.id.action_acc_upgrade);
          upgrade.setVisible(false);
      }
  
      return true;
  }
  </code></pre>
  
  <p>If I run this through the debugger, it reaches the line <code>if(isPaid())</code> and then evaluates it as true, so goes into the setVisible part. The item still shows up in the menu, though.</p>
  
  <p>I also tried removing the item from the menu instead of hiding it; the debugger shows that the item is removed, but then it still shows up when the menu is displayed.</p>
  
  <p>How can I hide/remove this item?</p>
  
  <h2>Edit</h2>
  
  <p>I'm using a navigation drawer to hold the menu. This is set up in onCreate as follows:</p>
  
  <pre><code>// Set up toolbar
  Toolbar toolbar = findViewById(R.id.toolbar);
  setSupportActionBar(toolbar);
  
  // Set up navigation drawer
  DrawerLayout drawer = findViewById(R.id.drawer_layout);
  ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
          this, drawer, toolbar, R.string.nav_drawer_open, R.string.nav_drawer_close);
  drawer.addDrawerListener(toggle);
  toggle.syncState();
  </code></pre>
  
  <p>I suspect that this somehow bypasses onPrepareOptionsMenu etc? Is there a way of adding a listener which is called when the "open navigation drawer" button is clicked?  I can only find callbacks for the drawer being opened or closed, and they're called after the drawer has moved - I need to call them before.</p>