I created a popup menu. I need to hide a particular item from popup menu on condition, I tried this below code but it doesn't work and shows "unexpectedly your app has been stopped". I used findViewById
and setEnabled(false)
.
Is there any other way to hide an item from popup menu? Please help with this.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch(item.getItemId()){
case R.id.addMessage_Action:
AddMessage();
break;
case R.id.dropMenuAction:
menuItemView = findViewById(R.id.dropMenuAction);
PopupMenu popup = new PopupMenu(this, menuItemView);
MenuInflater inflater = popup.getMenuInflater();
inflater.inflate(R.menu.popupmenu_for_message_delete, popup.getMenu());
popup.show();
popup.setOnMenuItemClickListener(this);
if(Global.lock == true)
findViewById(R.id.lock_message).setEnabled(false);
else
findViewById(R.id.unlock_message).setEnabled(false);
break;
}
return false;
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…