Setting PopupMenu menu items programmatically Setting PopupMenu menu items programmatically android android

Setting PopupMenu menu items programmatically


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.


Just create the popup menu registering the view the popup will show underneath and use the getMenu() method to add the values. Don't forget to call show();

PopupMenu menu = new PopupMenu(this, view);menu.getMenu().add("titleRes");menu.show();


Try this:

Dynamic_PopUpMenu.setOnClickListener(new View.OnClickListener() {    @Override    public void onClick(View v) {        PopupMenu menu = new PopupMenu(DialogCheckBox.this, v);        menu.getMenu().add("AGIL");                 menu.getMenu().add("AGILarasan");        menu.getMenu().add("Arasan");        menu.show();    }});