title: How to hide menu item in android action bar?
body: <p>My goal is to hide one of the menu items in the action bar and show another after clicking on menu item. In my application, i am using <code>Toolbar</code>. I have already looked for many other questions and did not find what I needed. Any help will be appreciated. I tried code below, but this crashes app after click.</p>
  
  <pre><code>public boolean onOptionsItemSelected(MenuItem item) {
      final SwipeRefreshLayout mySwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swiperefresh);
      switch (item.getItemId()) {
          case R.id.action_next:
              //code
              MenuItem secondItem = (MenuItem) findViewById(R.id.action_next);
              secondItem.setVisible(false);
              return true;
  
          case R.id.action_previous:
              //code
              return true;
          default:
              return super.onOptionsItemSelected(item);
      }
  }
  </code></pre>