我创建了一个弹出菜单.我需要在条件下隐藏弹出菜单中的特定项目,我尝试了下面的代码,但它不起作用并显示"意外地你的应用程序已被停止".我用过findViewById和setEnabled(false).
有没有其他方法可以隐藏弹出菜单中的项目?请帮忙.
@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;
}
Run Code Online (Sandbox Code Playgroud)