Android Create a simple menu programmatically

后端 未结 5 946
遥遥无期
遥遥无期 2021-02-01 12:36

I\'m trying to create a simple menu with one button that will call a method to clear the array. I don\'t want to use xml because all I need is one button.

Something like

5条回答
  •  臣服心动
    2021-02-01 12:57

    Here i implemented popup menu dynamically by using a click listener.

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

提交回复
热议问题