I am using NavigationDrawer with ActionBarSherlock. When I click on menu items onMenuItemClick()
methods don't get called.
The code:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
if (mDrawerLayout.isDrawerOpen(mDrawerList)) {
mDrawerLayout.closeDrawer(mDrawerList);
} else {
mDrawerLayout.openDrawer(mDrawerList);
}
}
return super.onOptionsItemSelected(item);
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList);
return super.onPrepareOptionsMenu(menu);
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
mDrawerToggle.syncState();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mDrawerToggle.onConfigurationChanged(newConfig);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
setTitle(AndroidUtils.getTitle());
SubMenu subMenu1 = menu.addSubMenu(null);
subMenu1.add(getString(R.string.save_loc)).setIcon(android.R.drawable.ic_menu_save).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
...
}
});
subMenu1.add(getString(R.string.save_em)).setIcon(android.R.drawable.ic_dialog_email).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
...
}
});
MenuItem subMenu1Item = subMenu1.getItem();
subMenu1Item.setIcon(android.R.drawable.ic_menu_share);
subMenu1Item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
return super.onCreateOptionsMenu(menu);
}
Since you are already using onOptionsItemSelected, have you considered processing all of your menu items in there instead? Like this: