title: How to add a menu in a fragment?
body: <p>When I use a fragment, I don't get the menu in the ActionBar. I don't know where is the problem with the code despite the implementation of the onCreateOptionsMenu() method. Here's the code that I am using:</p>
  
  <pre><code>public class LesAvis extends Fragment {
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState) {
      setHasOptionsMenu(true);
      View rootView = inflater.inflate(R.layout.avis, container,false);
      ListView listeAvis = (ListView) rootView.findViewById(R.id.listView);
      return rootView;
  
  }
  
  @Override
  public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
      inflater.inflate(R.menu.my_menu, menu);
      super.onCreateOptionsMenu(menu,inflater);
  }
  
  }
  </code></pre>
  
  <p>However, when I use this part of code for implementing the onCreateOptionsMenu() method, I get what I want(the menu in my actionbar):</p>
  
  <pre><code>@Override
  public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
      menu.add("Compte")
      .setIcon(R.drawable.ic_compte)
      .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
      menu.add("Compte")
      .setIcon(R.drawable.ic_historique)
      .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
      menu.add("Compte")
      .setIcon(R.drawable.ic_param)
      .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
  }
  </code></pre>