title: How to sort menu items in the an android app's options menu?
body: <p>I have an options menu created  and filled with several menu items. For some reason the order of the menu items when they are added is not as desired. </p>
  
  <p>To guarantee the menu items are shown in the order we want it to be, a sort step is needed after the creation. But I have searched the android dev documents and found no way of doing this (or just I did not find it).</p>
  
  <p>Is there any workaround to achieve this? Please advise.</p>
  
  <p>Thanks!</p>
  
  <p>Some sample code:</p>
  
  <pre><code>public boolean onCreateOptionsMenu(Menu menu) {
  
      menu.add("menuItem1");
  
      menu.add("menuItem2");
  
      // after this I want to sort the items
  
      ArrayList&lt;MenuItem&gt; list = new ArrayList&lt;MenuItem&gt;();
  
      for(int i = 0; i &lt; menu.size(); i ++) {
          list.add(menu.getItem(i));
      }
  
      Collections.sort(list, new SampleComparator());
  
      // But then I don't know how to add the sorted list of menu items back
  }                
  </code></pre>