(First, I use ActionbarSherlock through HoloEverywhere, although I don't know that this is due to the problem.)
I have an activity with three fragments. Each fragment has its own menu items, and they all have some menu items. I already learned from StackOverflow that it is not allowed to add menu items to Activity and then add more items to Fragment(I tried ... it causes strange errors). Thus, it Activitydoes not have a menu, but each fragment. However, I'm still trying to avoid duplicate menu entries in each xml fragment. For this, I have one xml menu for each fragment and one xml menu that they all share. For example, I have:
fragment_1_menu.xml
fragment_2_menu.xml
all_fragments_menu.xml
and in Fragment1I'm trying to import both fragment_1_menu.xml, and all_fragments_menu.xml:
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.all_fragments_menu, menu);
inflater.inflate(R.menu.fragment_1_menu, menu);
super.onCreateOptionsMenu(menu, inflater);
}
When I do this, it almost works, but in my case one of the menu items from is missing all_fragments_menu. I do not mean its empty hole in the menu ... I mean that it is not represented at all in the menu. XML identifiers are unique and map to different ints in R.java. It seems like it should work. I do the same with Fragment2, except that fragment_2_menu.xmlit has no items, in which case all menu items look as expected.
Should this work? Did I miss something?
source
share