[英]Android access menu from onOptionsItemSelected
I have the following in my activity (sorry new to Java/Android): 我的活动中有以下内容(对Java / Android来说很抱歉):
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.options, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
case R.id.selectItem:
// menu.add(...) --> how to get the menu instance?
return true;
default:
return super.onOptionsItemSelected(item);
}
}
I am wondering, how can I access a menu object in onOptionsItemSelected? 我想知道如何在onOptionsItemSelected中访问菜单对象? For example, how would I go about adding a new view to the options menu based on the selection of an existing menu item?
例如,如何根据现有菜单项的选择向选项菜单添加新视图? Is the answer related to "onPrepareOptionsMenu"?
答案与“ onPrepareOptionsMenu”有关吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.