从SherlockFragmentActivity重写onOptionsItemSelected [英] Overriding onOptionsItemSelected from SherlockFragmentActivity

查看:174
本文介绍了从SherlockFragmentActivity重写onOptionsItemSelected的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

昨天,我发现了一个伟大的图书馆,让我有一个脸谱菜单上的操作栏,当pressed,将滑动从左边的菜单项的左上角的按钮。

Yesterday, I found a great library that allowed me to have a "facebook menu" with a button on the top left of an action bar which, when pressed, would slide in a menu of items from the left.

现在的问题是,我想利用ActionBarSherlock库,以及确保我的应用程序与操作栏中的向后兼容。当使用库的本人,除其他事项外,需要重写onOptionsItemSelected这样:

The problem is that I wish to make use of the ActionBarSherlock library as well to make sure that my application is backwards compatible with the action bar. When using the library I, among other things, need to override onOptionsItemSelected as such :

@Override
public boolean onOptionsItemSelected(MenuItem item) 
{
    int id = item.getItemId();

    if (id == android.R.id.home) {

        rbmView.toggleMenu();

        return true;

    } else {
        return super.onOptionsItemSelected(item);
    }
}

现在我走进图书馆,看到开发商已作出onOptionsItemSelected 最后。我删除它,并试图再次重写它才发现,该产品是,每当我preSS按钮没有任何反应。什么都没有。

Now I went into the library and saw that the developer had made onOptionsItemSelected final. I removed it and tried overriding it again only to find that the product was that whenever I press the button nothing happens. Nothing at all.

我怎么会去使用darvds_ribbonmenu库以及actionbarsherlock任何想法?

Any idea on how I would go about using the darvds_ribbonmenu library along with actionbarsherlock?

推荐答案

原来,采用ABS当你需要指定菜单项的命名空间,以确保你覆盖正确的方法。我的解决办法如下:

Turns out that when using ABS you will need to specify the namespace of MenuItem to make sure that you're overriding the correct method. My solution was as follows :

@Override
public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) 
{
    int id = item.getItemId();
    Log.d("item ID : ", "onOptionsItemSelected Item ID" + id);
    if (id == android.R.id.home) {
        rbmView.toggleMenu();

        return true;

    } else {
        return super.onOptionsItemSelected(item);
    }
}

这篇关于从SherlockFragmentActivity重写onOptionsItemSelected的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆