【发布时间】:2012-02-25 23:46:06
【问题描述】:
在android开发站点,我看到onOptionsItemSelected的解释,在return一侧,它说:
boolean Return false to allow normal menu processing to proceed, true to consume it here.
对不起我的笨蛋,谁能说明这句话的意思,我应该返回 true 还是 false > 正常情况下?
【问题讨论】:
在android开发站点,我看到onOptionsItemSelected的解释,在return一侧,它说:
boolean Return false to allow normal menu processing to proceed, true to consume it here.
对不起我的笨蛋,谁能说明这句话的意思,我应该返回 true 还是 false > 正常情况下?
【问题讨论】:
如果您处理菜单项,则应返回 true,否则应返回 super.onOptionsItemSelected(item)。
例如
public boolean onOptionsItemSelected(MenuItem item)
{
switch (item.getItemId())
{
case R.id.option1:
handleOption1();
return true;
case R.id.option2:
handleOption2();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
【讨论】:
false,不是吗?文档说“默认实现只是返回 false 以进行正常处理”
我认为你可以让系统处理它:
return super(...);
否则,返回 TRUE/FALSE 仅表示如果您正在处理的案例已完全处理该事件,则返回 TRUE。如果不是这样,则返回 false,系统应该将偶数分派给正确的处理程序。
【讨论】: