Android Actionbarsherlock:菜单按钮在Froyo中工作,但在ICS中不工作?

Android Actionbarsherlock:菜单按钮在Froyo中工作,但在ICS中不工作?,android,button,actionbarsherlock,Android,Button,Actionbarsherlock,我制作了一个应用程序,它在Froyo及以下版本上运行良好——但在ICS及以上版本上,当我点击菜单按钮(更新链接、图片链接活动和搜索活动链接)时,什么都不会发生。当我点击ICS中的一个按钮时,我手机上的按钮会亮起,但活动不会像Froyo上那样打开。我很少修改ActionBarSherlock。我从toast消息中知道,单击已在ICS中注册。但活动并未开始。在LogCat中,我得到了一个 window already focused ignoring focus gain of com.androi

我制作了一个应用程序,它在Froyo及以下版本上运行良好——但在ICS及以上版本上,当我点击菜单按钮(更新链接、图片链接活动和搜索活动链接)时,什么都不会发生。当我点击ICS中的一个按钮时,我手机上的按钮会亮起,但活动不会像Froyo上那样打开。我很少修改ActionBarSherlock。我从toast消息中知道,单击已在ICS中注册。但活动并未开始。在LogCat中,我得到了一个

window already focused ignoring focus gain of com.android.internal.view.iinputmethodclient
每次我点击其中一个按钮。我有一个猜测,也许是在这附近,问题可能是:

public boolean onCreateOptionsMenu(Menu menu) {
    //Used to put dark icons on light action bar
    boolean isLight = true;


    menu.add("Save")
        .setIcon(isLight ? R.drawable.ic_stilling1 : R.drawable.ic_stilling1)
        .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

    menu.add("Search")
        .setIcon(isLight ? R.drawable.ic_search_inverse : R.drawable.ic_search)
        .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

    menu.add("Opdatér")
        .setIcon(isLight ? R.drawable.ic_refresh_inverse : R.drawable.ic_refresh)
        .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

    return true;
}

public boolean onOptionsItemSelected(MenuItem item) {
    //This uses the imported MenuItem from ActionBarSherlock
    Toast.makeText(this, "Got click: " + item.toString(), Toast.LENGTH_SHORT).show();

    if (item.toString()=="Save"){

        startActivity (new Intent(getApplicationContext(), F3Activity.class));

        return true;
    }

    if (item.toString()=="Search"){

        startActivity (new Intent(getApplicationContext(), SearchActivity.class));

        return true;
    }

    if (item.toString()=="Opdatér"){

        startActivity (new Intent(getApplicationContext(), ABSTabsViewPagerActivity.class));

        return true;
    }



    return true;
}
正如你所看到的,我是编程方面的高手:-)有人知道我如何让按钮在ICS中做出反应吗?我在我自己的旧HTC Desire上测试了果冻豆,在我朋友的三星Galaxy II和III上测试了ICS,结果完全相同

[编辑]:这使它工作起来:

if (item.getTitle()=="Save")
if (item.getTitle()=="Save")
而不是

if (item.toString()=="Save")
一个初学者的错误,我知道;-)

这使它起作用了:

if (item.getTitle()=="Save")
if (item.getTitle()=="Save")
而不是

if (item.toString()=="Save")
用于字符串比较。正确的方法是

if ("Save".equals(item.getTitle()))

考虑给你的菜单项一个ID,并用它来判断哪个菜单项被点击。

ActionBarSherlock中99.9%的东西在2.x以上的每个平台上都能工作。菜单不在.1%中。如果我想确保这些活动在ICS/ABS中打开,我可以用另一种方式启动它们吗?我还将返回super.onXYZ而不是true这两种方法——特别是如果第二种方法中不满足您的条件之一。