I use SherlockListActivity, I created ActionBar with one item & its clickListener when i click on it for first time after creating activity, doesn't call onMenuItemClick, but in every click after first click, work with no problem
Why ?
private void BuildTopActionBar() {
BitmapDrawable bg = (BitmapDrawable) getResources().getDrawable(
R.drawable.ic_action_bg);
bg.setTileModeXY(TileMode.REPEAT, TileMode.REPEAT);
getSupportActionBar().setBackgroundDrawable(bg);
this.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
this.getSupportActionBar().setHomeButtonEnabled(true);
this.getSupportActionBar().setTitle("bookmarks");
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// This is called when the Home (Up) button is pressed in the Action Bar.
finish();
return true;
case add_bookmark_item:
// add
item.setOnMenuItemClickListener(new OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
customAmbilWarnaDialog dialog = new customAmbilWarnaDialog(
BookMarksActivity.this, 0xffffffff,
new OnAmbilWarnaListener() {
public void onCancel(
customAmbilWarnaDialog dialog) {
}
public void onOk(customAmbilWarnaDialog dialog,
int color, String name, int hasName) {
myDbHelper.AddNewBookmark(name,
currentPageNum, color, hasName);
// code
lv.smoothScrollToPosition((lv.getCount() - 1));
}
});
dialog.show();
return true;
}
});
}
return super.onOptionsItemSelected(item);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(0, add_bookmark_item, 0, "add bookmark")
.setIcon(R.drawable.bookmark_add)
.setShowAsAction(
MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW
| MenuItem.SHOW_AS_ACTION_ALWAYS);
return true;
}