我创建了一个弹出菜单.我需要从弹出菜单中隐藏特定的项目,我尝试下面的代码,但它不起作用,并显示“意外您的应用程序已被停止”.我使用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; }