2

I'm adding a SubMenu at runtime and everything works great. I just have a problem: how to set showAsAction="always" on a runtime-added SubMenu? There is no method to achieve that and if don't set it I can't find any way to have it shown in the Action Bar. Thanks for helping

3 Answers3

4

Don't know if this is too late or not, but SubMenu has as function called getItem() which returns a MenuItem. You can then get this MenuItem, and call setShowAsAction() afterwards. Hope this helps!!!

cwhite
  • 41
  • 2
1

Call yourSubMenu.getItem(). This give you MenuItem that represent the SubMenu.

deW1
  • 5,562
  • 10
  • 38
  • 54
0

If im right then MenuItem = item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

FD_
  • 12,947
  • 4
  • 35
  • 62
Jerry Wattre
  • 204
  • 2
  • 8
  • yeah i thought that but SubMenu is not a MenuItem, isn't it? In your answer you're calling setShowAsAction on a MenuItem not on a SubMenu – Francesco Ambrosini Jan 31 '14 at 16:11
  • 1
    How can I try it? I have `SubMenu menu;` from here how should I call your `MenuItem.setShowAsAction()`? Do you mean calling it on one of the child items of my SubMenu? – Francesco Ambrosini Jan 31 '14 at 16:17