roboguy12 roboguy12 - 1 year ago 87
Android Question

Setting PopupMenu menu items programmatically

I have a

and I know the usual way to associate a menu to it is to use
popup.getMenuInflater().inflate(, popup.getMenu());
or something of the like. My problem is, I have an array of items that I want in the menu and I need to be able to change them programmatically in Java. How can I do this?

Thank you!

Answer Source

Just figured it out; for anyone who runs into this same problem you just do:

popup.getMenu().add(groupId, itemId, order, title);

for each MenuItem you want to add.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download