title: Programatically fire action bar menu item in Android
body: <p>I have actionbar with menu item on the bar. When I click on the refresh icon I have method that shows up the progress bar.</p>
  
  <p>I would like to do the on loading of this activity. Hence, I tried calling the refresh icon item click programatically:</p>
  
  <pre><code>onOptionsItemSelected(menu.findItem(R.id.action_Refresh)); 
  </code></pre>
  
  <p>I am calling the above after creating the menu.</p>
  
  <p>But this gives null pointer exception on load my data. If I click on refresh button it is working fine, but if I call it programmatically I get an error.</p>
  
  <p>Here is what I have:</p>
  
  <pre><code> @Override
  public boolean onCreateOptionsMenu(Menu menu) 
  {
      this.optionsMenu = menu;
      getMenuInflater().inflate(R.menu.main, menu);
  
      onOptionsItemSelected(menu.findItem(R.id.action_Refresh));
  
      return true;
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) 
  {
      switch (item.getItemId()) 
      {
      case R.id.action_about:
          aboutapp();
          return true;
  
      case R.id.action_Refresh:
          Log.e("REfressh","Clicked");
          Mapsthree.refreshValue = 0;
          timer = new Timer();
          timerMethod();
          setRefreshActionButtonState(true);
          displayView(1);
          return true;
  
      default:
          return super.onOptionsItemSelected(item);
      }
  }
  
  private void timerMethod()
  {
      timer.scheduleAtFixedRate(new TimerTask() 
      {
          @Override
          public void run() 
          {
              updateProgressBar();
          }
  
      }, 0, 800);
  }
  
  private void updateProgressBar() 
  {
      runOnUiThread(new Runnable() 
      {
          public void run() 
          {
              if (Maps.refreshValue == 1)
              {
                  setRefreshActionButtonState(false);
                  timer.purge();
                  timer.cancel();
              }
          }
      });
  }
  
  public void setRefreshActionButtonState(final boolean refreshing) 
  {
      if (optionsMenu != null) 
      {
          final MenuItem refreshItem = optionsMenu.findItem(R.id.action_Refresh);
          if (refreshItem != null) 
          {
              if (refreshing) 
              {
                  refreshItem.setActionView(R.layout.actionbar_indeterminate_progress);
              } 
              else 
              {
                  refreshItem.setActionView(null);
              }
          }
      }
  }
  </code></pre>
  
  <p>Is it possible to call a menu item programmatically? if so how?</p>
  
  <p>Thanks!</p>