onOptionsItemSelected not called when using actionLayout (SherlockActionBar)

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);
}

You'll have to add your own OnClickListener and explicitly call onOptionsItemSelected:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuItem awesomeMenuItem = menu.findItem(R.id.action_awesome);
    View awesomeActionView = menuItem.getActionView();
    awesomeActionView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onOptionsItemSelected(awesomeMenuItem));
        }
    });
}

P.S: Don't know why it doesn't work out of the box.

Tags:

Android