Using getItemId() always get 0 in onActionItemClicked

891 Views Asked by At

I'm using com.actionbarsherlock.view.ActionMode and when I try to get the clicked item id like this:

    public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            Toast.makeText(WeiboActivity.this, "Got click: " + item.getItemId(), Toast.LENGTH_SHORT).show();
            return false;
        }
    }

it's always:

Got click: 0

So what is the right code to get the clicked item id?

1

There are 1 best solutions below

0
On

You need to include item id in your call when you created the menu item

menu.add(Menu.NONE, R.id.menu_test, Menu.NONE, R.string.menu_test)