title: How to implement a menuitem click listener inside a fragment in android
body: <p>I have MenuItems in the ActionBar and I am using Fragments inside ViewPager. Now I would like to handle onMenuItemClickListener event inside my fragment. It works fine inside Main Activity. But not inside Fragments. And also it doesn't fetch any error.</p>
  
  <p>Here is the methods that I tried. Both works fine inside Activity.</p>
  
  <p>First method:</p>
  
  <pre><code>public boolean onCreateOptionsMenu(Menu menu) {
      MenuItem item = menu.findItem(R.id.grid_view);
      item.setOnMenuItemClickListener(new OnMenuItemClickListener() {
          @Override
          public boolean onMenuItemClick(MenuItem item) {
             Log.v("test","dfsfdsfasd");
              return true;
          }
      });
      return true;
  }
  </code></pre>
  
  <p>Second Method:</p>
  
  <pre><code>public boolean onOptionsItemSelected(MenuItem item)
  {
      switch(item.getItemId())
      {
      case R.id.grid_view:
      {
          Log.v("Log:","grid_view item pressed");
          return true;
      }
  
      case R.id.list_view:
      {
          Log.v("Log:","list_view item pressed");
          return true;
      }
      default:
          return true;
      }
  }
  </code></pre>
  
  <p>Any help on how to achieve this will be appreciated.</p>