gpt4 book ai didi

android - 为什么 ActionBarSherlock 没有响应?

转载 作者:太空狗 更新时间:2023-10-29 16:20:57 25 4
gpt4 key购买 nike

我是 android 的菜鸟,我正在使用 ActionBarSherlock 的菜单栏来访问菜单。在低于 API 11 的 android API 上一切正常,但对于任何 API 11 及以上,菜单栏/菜单项都没有响应。当我单击它们时,菜单项会突出显示,但它们不会执行。就好像菜单项已经失去了他们的听众是不是有一个我忘记实现的设置?非常感谢任何帮助。

我的代码:

//My Sherlock wrapper 
ActionBarSherlock mSherlock = ActionBarSherlock.wrap(this);

//OnCreate
setTheme(R.style.Theme_Sherlock);
mSherlock.setContentView(R.layout.main);

//Menu Methods
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch (item.getItemId())
{
case 1: // id from the xml file
Intent i = new Intent("com.bmoney.GSCC.OPTIONS");
startActivity(i);
return true; // we handled the click, dont pass it up the chain

case 2: // id from the xml file
Intent i2 = new Intent("com.bmoney.GSCC.PREFS");
startActivity(i2);
return true;
}
return false;
}

@Override
public boolean onCreateOptionsMenu(android.view.Menu menu) {
// TODO Auto-generated method stub
return mSherlock.dispatchCreateOptionsMenu(menu);

}


@Override
public boolean onCreateOptionsMenu(Menu menu) { //<-- has Sherlock Menu Import

menu.add(0,1,0,"Preferences").setIcon(R.drawable.ic_action_example).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
menu.add(0,2,0,"Help").setIcon(R.drawable.info).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

return true;
}

最佳答案

如果我不得不猜测,您对 MenuItem 的导入是针对 android.view.MenuItem 的,而不是 Sherlock 的等价物。

如果是这样,我建议:

  • 您将 @Override 添加到 onOptionsItemSelected()

  • 您删除所有 android.view.* 导入,然后将它们重新添加为 Sherlock 导入(例如,通过 Eclipse 中的 Ctrl-Shift-O)

  • 您合并两个 onCreateOptionsMenu() 方法,使用带有 Sherlock 导入的方法

关于android - 为什么 ActionBarSherlock 没有响应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14970367/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com