Setting PopupMenu menu items programmatically Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Setting PopupMenu menu items programmatically without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I have a PopupMenu and I know the usual way to associate a menu to it is to use popup.getMenuInflater().inflate(R.menu.my_menu, 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?

Answer

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.

We are here to answer your question about Setting PopupMenu menu items programmatically - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji