title: Menu Ordering differences due to Fragment and Activity hierarchy. (onCreateOptionsMenu)
body: <p><strong>Background</strong></p>
  
  <p>Developing for Android 3.0, I have a <code>HostActivity</code> that is the superclass of <code>NotebooksActivity</code> and <code>NoteActivity</code>. <code>NotebooksActivity</code> includes a fragment, <code>NotebooksFragment</code>.</p>
  
  <p>In <code>HostActivity</code>, I include a menu that I want to appear at the rightmost end of the options menu in the ActionBar, <strong>i.e. all menu items in subclasses of <code>HostActivity</code> should appear to the left of the menu items added in <code>HostActivity</code>.</strong></p>
  
  <p>Menu inflation in <code>HostActivity</code>:</p>
  
  <pre><code>@Override
  public boolean onCreateOptionsMenu(Menu menu) {
      final MenuInflater inflater = getMenuInflater();
      inflater.inflate(R.menu.host_menu, menu);
      return super.onCreateOptionsMenu(menu);
  }
  </code></pre>
  
  <p><strong>The Problem</strong></p>
  
  <p>When I add menu items in <code>NoteActivity</code>, I achieve the desired order as expected: </p>
  
  <pre><code>@Override
  public boolean onCreateOptionsMenu(Menu menu) {
      MenuInflater inflater = getMenuInflater();
      inflater.inflate(R.menu.notebook_menu, menu);
      return super.onCreateOptionsMenu(menu);
  }
  </code></pre>
  
  <p>However, when I add menu items in <code>NotebooksFragment</code>, because of how Fragments work, <code>onCreateOptionsMenu</code> is called after the same method in <code>HostActivity</code>, <strong>resulting in <code>HostActivity</code>'s menu items appearing before <code>NotebooksFragment</code>'s.</strong></p>
  
  <pre><code>@Override
  public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
      inflater.inflate(R.menu.notebooks_menu, menu);
      SearchView sv = new SearchView(getActivity());
      sv.setOnQueryTextListener(this);
      menu.findItem(R.id.search_notebooks).setActionView(sv);
  
      super.onCreateOptionsMenu(menu, inflater);
  }
  </code></pre>
  
  <p>How can I achieve my desired menu ordering?</p>