ionLayout当onOptionsItemSelected不

ionLayout当onOptionsItemSelected不

本文介绍了使用actionLayout当onOptionsItemSelected不叫(SherlockActionBar)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个菜单项使用actionLayout时的方法,onOptionsItemSelected不被调用。我缺少的东西,或者是一个已知的问题SherlockActionBar?

The method onOptionsItemSelected isn't being called when using actionLayout in a menu item.Am I missing something, or is it a known problem with SherlockActionBar?

活动

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getSupportMenuInflater();
    inflater.inflate(R.menu.article, menu);

    super.onCreateOptionsMenu(menu);

    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    Log.d(TAG, "onOptionsItemSelected()");

    switch (item.getItemId()) {
        case android.R.id.home:
            finish();
            return true;
        case R.id.menu_item_comment:
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}

菜单

<item android:id="@+id/menu_item_comment"
    android:showAsAction="ifRoom"
    android:actionLayout="@layout/action_bar_comment_layout"/>

推荐答案

好了,你必须设置onClickListener上actionLayout接收回调。我这样做是这样的:

well, you have to set onClickListener on that actionLayout to receive callback. I do it like this:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getSupportMenuInflater().inflate(R.menu.map_menu, menu);
    for (int i = 0; i < menu.size(); i++) {
        MenuItem item = menu.getItem(i);
        if (item.getItemId() == R.id.menu_more) {
            itemChooser = item.getActionView();
            if (itemChooser != null) {
                itemChooser.setOnClickListener(this);
            }
        }
    }
    return super.onCreateOptionsMenu(menu);
}

这篇关于使用actionLayout当onOptionsItemSelected不叫(SherlockActionBar)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 17:23