我想將上下文菜單應用到一個文本框。我想設置剪切,複製,過去,當字符串剪貼板是空的,當字符串剪貼板不空,我想剪切,複製,過去被啓用。如何disble菜單項在Android中的ContextMenu
首先我將可變剪貼板分配給empy String clipboard =「」;
然後
公共無效onCreateContextMenu(文本菜單菜單,視圖V, ContextMenuInfo menuInfo){
getMenuInflater().inflate(R.menu.context, menu);
if(clipboard ==""){
menu.findItem(R.id.action_cut).setEnabled(false);
menu.findItem(R.id.action_copy).setEnabled(false);
menu.findItem(R.id.action_paste).setEnabled(false);}else{
menu.findItem(R.id.action_cut).setEnabled(true);
menu.findItem(R.id.action_copy).setEnabled(true);
menu.findItem(R.id.action_paste).setEnabled(true);}
super.onCreateContextMenu(menu, v, menuInfo);
}
,但它無法正常工作......即使clicpboard是空的,但項目仍菜單啓用。
你混淆Java中的字符串匹配。它的clipboard.equals(「」)而不是==作比較 – humblerookie