如果我在上下文菜单或普通菜单中有一个可勾选的项目,我该如何防止菜单在该项目被选中时关闭?
最佳答案
这取决于您使用什么库来创建菜单(ABS/ABC/?),但通常我认为您在处理项目点击时只需要return false
。 return
值让系统知道点击是否被处理。通常您会将其设置为 true
,然后系统将执行关闭菜单的默认行为。这是上下文菜单的示例:
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
switch (item.getItemId()) {
case R.id.edit:
editNote(info.id);
return true; // return false here
case R.id.delete:
deleteNote(info.id);
return true; // or here
default:
return super.onContextItemSelected(item);
}
}
关于android - 防止上下文菜单在单击项目(特别是复选框项目)时关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2332416/