Skip to content Skip to sidebar Skip to footer

Remove Popup Menu Item Programmatically

I'm inflating a popup menu in my application. I've created a popmenu xml like below. Song_popup xml Copy

Implementation of condition is totally up to you.


and this is how you can handle menu item clicks:

popup.setOnMenuItemClickListener(newPopupMenu.OnMenuItemClickListener() {
    @OverridepublicbooleanonMenuItemClick(MenuItem menuItem) {
        if(menuItem.getItemId() == R.id.play_next){
            Toast.makeText(YourActivity.this, "Play_next", Toast.LENGTH_SHORT).show();
            returntrue;
        }
        returnfalse;
    }
});

Solution 2:

You can do it simpily. ex-

if (popup != null && yourcondition){
      MenuItem menuitem=    popup.getMenu().getItem(1);
      menuitem.setVisible(false);
    }

Solution 3:

Unless I’m missing something, it should be as simple as e.g.:

if (doNotShowAddQueue) {
    finalMenumenu= popup.getMenu();
    menu.removeItem(R.id.add_queue);
}

Post a Comment for "Remove Popup Menu Item Programmatically"