Reputation: 45
I want to hide an item in Action Bar Sherlock. I try it:
public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) {
switch (item.getItemId()) {
case 2131165381:
item.setVisible(false);
supportInvalidateOptionsMenu();
CopyOfAsyncLoadTasks.run(this);
item.setVisible(true);
break;
What I am doing wrong?
Upvotes: 0
Views: 608
Reputation: 33495
I suggest you to use rather resource id
of <item>
instead of your "ambicious" number.
switch (item.getItemId()) {
case R.id.myItem:
menu.findItem(R.id.myItem).setVisible(false);
break;
...
}
From first look at your code i don't know exactly what number 2131165381 is? If you'll work in team it'll be not very human-readable especially for another person.
Note: To get more control over menu i recommend you to create second menu variable e.q:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
this.menu = menu;
...
}
Upvotes: 1