I'm a noob to android and I am using ActionBarSherlock's menu bar to access menus. Everything works fine on android APIs lower than API 11, but for any API 11 and Above the menu bar/menu items are unresponsive. The menu items highlight when I click them, but they don't execute. It's almost as if the menu items have lost their listener is there a setting that I forgot to implement? any help is greatly appreciated.
My Code:
//My Sherlock wrapper
ActionBarSherlock mSherlock = ActionBarSherlock.wrap(this);
//OnCreate
setTheme(R.style.Theme_Sherlock);
mSherlock.setContentView(R.layout.main);
//Menu Methods
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch (item.getItemId())
{
case 1: // id from the xml file
Intent i = new Intent("com.bmoney.GSCC.OPTIONS");
startActivity(i);
return true; // we handled the click, dont pass it up the chain
case 2: // id from the xml file
Intent i2 = new Intent("com.bmoney.GSCC.PREFS");
startActivity(i2);
return true;
}
return false;
}
@Override
public boolean onCreateOptionsMenu(android.view.Menu menu) {
// TODO Auto-generated method stub
return mSherlock.dispatchCreateOptionsMenu(menu);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) { //<-- has Sherlock Menu Import
menu.add(0,1,0,"Preferences").setIcon(R.drawable.ic_action_example).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
menu.add(0,2,0,"Help").setIcon(R.drawable.info).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
return true;
}
I think you should add an OnMenuItemClickListener to your menu items when you add them in onCreateOptionsMenu. Then add the OnMenuItemSelected method and implement the code you have in onOptionItemSelected in the OnMenuItemSelected method. So you should have...
@Override
public boolean onMenuItemClick(MenuItem item) {
// Code from inside onoptionItemSelected
}