【发布时间】:2011-06-03 07:35:20
【问题描述】:
在我的项目中,我有带有选项菜单的活动。我覆盖onOptionsItemSelected 方法并将我的处理程序添加到菜单项(switch-case 块)。但是在一个处理程序中,我需要访问另一个菜单项,我该怎么做? findViewById 不起作用
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.visit:
//how to access another MenuItem from here?
return true;
}
...
【问题讨论】:
-
如何在尚未点击的情况下访问菜单项?请记住,您是从 onOptionsItemSelected() 访问它的,只有在选择菜单项时才会调用它。