So I\'m trying to grab my menu items off the ActionBar and set them into some variables to use later. Below is some basic test code that tries to set the variable during the
MenuItem.getItem(index) take index of the menu item instead of id of menu item so use MenuItem.findItem
which take menu item id as:
mRefresh = menu.findItem(R.id.refresh); //item id
OR
mRefresh = menu.getItem(0); //item index
getItem(int)
returns a MenuItem at a specific index, while findItem(int)
returns a MenuItem corresponding to the resource ID that is given. Call findItem
instead of getItem
.
http://developer.android.com/reference/android/view/Menu.html#findItem(int)