I create the menu items of my Actionbar programmatically, due to an error in Android when you have two Fragments , each with its own menu.
I am creating a menu in onCreateActionMode MultiChoiceModeListener . If there are more than 4 menu items, all items are inserted into the overflow menu of the context action panel.
This happens in portait and landscape mode, but only when the layout is in non-display mode (for example, both fragments are not displayed). I am testing Galaxy Nexus with Android 4.2
mListView = getListView(); mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); mListView.setMultiChoiceModeListener(new MultiChoiceModeListener() { @Override public boolean onCreateActionMode(android.view.ActionMode mode, android.view.Menu menu) { // Inflate the menu for the CAB menu.add(1, 0, 0, "Menu Item 1"); menu.add(1, 1, 1, "Menu Item 2"); menu.add(1, 2, 2, "Menu Item 3"); menu.add(1, 3, 3, "Menu Item 4"); menu.add(1, 4, 4, "Menu Item 5"); return true; } }
UPDATE
I narrowed down this problem, if there are more than 4 menu items, all items come into overflow. The length of the text label does not matter. I even set all the text to blank lines, and they were still forced to overflow. Setting IF_ROOM or ALWAYS does not seem to have an effect.
UPDATE 2
I have another Fragment that uses OnItemLongClickListener instead of MultiChoiceModeListener and I don't experience the same problem. I can put 10 menu items and it will display the first pair in the Actionbar and leave everything else in overflow, as expected.
UPDATE 3
A bit more information on this issue, but in Nexus 7 portrait mode, the problem still exists, but in tabletless mode (both fragments are not displayed), in Nexus 7 landscape mode the display menu items. The only thing I can come up with is counting the interval when using the MultiChoiceModeListener , which finds that there is no room in the action context bar.