Build 1.0_r1(from source)

android.view
Interface MenuItem


public interface MenuItem

Interface for direct access to a previously created menu item.

An Item is returned by calling one of the Menu.add(java.lang.CharSequence) methods.

For a feature set of specific menu types, see Menu.


Nested Class Summary
static interface MenuItem.OnMenuItemClickListener
          Interface definition for a callback to be invoked when a menu item is clicked.
 
Method Summary
 char getAlphabeticShortcut()
          Return the char for this menu item's alphabetic shortcut.
 int getGroupId()
          Return the group identifier that this menu item is part of.
 Drawable getIcon()
          Returns the icon for this item as a Drawable (getting it from resources if it hasn't been loaded before).
 Intent getIntent()
          Return the Intent associated with this item.
 int getItemId()
          Return the identifier for this menu item.
 ContextMenu.ContextMenuInfo getMenuInfo()
          Gets the extra information linked to this menu item.
 char getNumericShortcut()
          Return the char for this menu item's numeric (12-key) shortcut.
 int getOrder()
          Return the category and order within the category of this item.
 SubMenu getSubMenu()
          Get the sub-menu to be invoked when this item is selected, if it has one.
 CharSequence getTitle()
          Retrieve the current title of the item.
 CharSequence getTitleCondensed()
          Retrieve the current condensed title of the item.
 boolean hasSubMenu()
          Check whether this item has an associated sub-menu.
 boolean isCheckable()
          Return whether the item can currently display a check mark.
 boolean isChecked()
          Return whether the item is currently displaying a check mark.
 boolean isEnabled()
          Return the enabled state of the menu item.
 boolean isVisible()
          Return the visibility of the menu item.
 MenuItem setAlphabeticShortcut(char alphaChar)
          Change the alphabetic shortcut associated with this item.
 MenuItem setCheckable(boolean checkable)
          Control whether this item can display a check mark.
 MenuItem setChecked(boolean checked)
          Control whether this item is shown with a check mark.
 MenuItem setEnabled(boolean enabled)
          Sets whether the menu item is enabled.
 MenuItem setIcon(Drawable icon)
          Change the icon associated with this item.
 MenuItem setIcon(int iconRes)
          Change the icon associated with this item.
 MenuItem setIntent(Intent intent)
          Change the Intent associated with this item.
 MenuItem setNumericShortcut(char numericChar)
          Change the numeric shortcut associated with this item.
 MenuItem setOnMenuItemClickListener(MenuItem.OnMenuItemClickListener menuItemClickListener)
          Set a custom listener for invocation of this menu item.
 MenuItem setShortcut(char numericChar, char alphaChar)
          Change both the numeric and alphabetic shortcut associated with this item.
 MenuItem setTitle(CharSequence title)
          Change the title associated with this item.
 MenuItem setTitle(int title)
          Change the title associated with this item.
 MenuItem setTitleCondensed(CharSequence title)
          Change the condensed title associated with this item.
 MenuItem setVisible(boolean visible)
          Sets the visibility of the menu item.
 

Method Detail

getItemId

int getItemId()
Return the identifier for this menu item. The identifier can not be changed after the menu is created.

Returns:
The menu item's identifier.

getGroupId

int getGroupId()
Return the group identifier that this menu item is part of. The group identifier can not be changed after the menu is created.

Returns:
The menu item's group identifier.

getOrder

int getOrder()
Return the category and order within the category of this item. This item will be shown before all items (within its category) that have order greater than this value.

An order integer contains the item's category (the upper bits of the integer; set by or/add the category with the order within the category) and the ordering of the item within that category (the lower bits). Example categories are Menu.CATEGORY_SYSTEM, Menu.CATEGORY_SECONDARY, Menu.CATEGORY_ALTERNATIVE, Menu.CATEGORY_CONTAINER. See Menu for a full list.

Returns:
The order of this item.

setTitle

MenuItem setTitle(CharSequence title)
Change the title associated with this item.

Parameters:
title - The new text to be displayed.
Returns:
This Item so additional setters can be called.

setTitle

MenuItem setTitle(int title)
Change the title associated with this item.

Some menu types do not sufficient space to show the full title, and instead a condensed title is preferred. See Menu for more information.

Parameters:
title - The resource id of the new text to be displayed.
Returns:
This Item so additional setters can be called.
See Also:
setTitleCondensed(CharSequence)

getTitle

CharSequence getTitle()
Retrieve the current title of the item.

Returns:
The title.

setTitleCondensed

MenuItem setTitleCondensed(CharSequence title)
Change the condensed title associated with this item. The condensed title is used in situations where the normal title may be too long to be displayed.

Parameters:
title - The new text to be displayed as the condensed title.
Returns:
This Item so additional setters can be called.

getTitleCondensed

CharSequence getTitleCondensed()
Retrieve the current condensed title of the item. If a condensed title was never set, it will return the normal title.

Returns:
The condensed title, if it exists. Otherwise the normal title.

setIcon

MenuItem setIcon(Drawable icon)
Change the icon associated with this item. This icon will not always be shown, so the title should be sufficient in describing this item. See Menu for the menu types that support icons.

Parameters:
icon - The new icon (as a Drawable) to be displayed.
Returns:
This Item so additional setters can be called.

setIcon

MenuItem setIcon(int iconRes)
Change the icon associated with this item. This icon will not always be shown, so the title should be sufficient in describing this item. See Menu for the menu types that support icons.

This method will set the resource ID of the icon which will be used to lazily get the Drawable when this item is being shown.

Parameters:
iconRes - The new icon (as a resource ID) to be displayed.
Returns:
This Item so additional setters can be called.

getIcon

Drawable getIcon()
Returns the icon for this item as a Drawable (getting it from resources if it hasn't been loaded before).

Returns:
The icon as a Drawable.

setIntent

MenuItem setIntent(Intent intent)
Change the Intent associated with this item. By default there is no Intent associated with a menu item. If you set one, and nothing else handles the item, then the default behavior will be to call Context.startActivity(android.content.Intent) with the given Intent.

Note that setIntent() can not be used with the versions of Menu.add(java.lang.CharSequence) that take a Runnable, because Runnable.run() does not return a value so there is no way to tell if it handled the item. In this case it is assumed that the Runnable always handles the item, and the intent will never be started.

Parameters:
intent - The Intent to associated with the item. This Intent object is not copied, so be careful not to modify it later.
Returns:
This Item so additional setters can be called.
See Also:
getIntent()

getIntent

Intent getIntent()
Return the Intent associated with this item. This returns a reference to the Intent which you can change as desired to modify what the Item is holding.

Returns:
Returns the last value supplied to setIntent(android.content.Intent), or null.
See Also:
setIntent(android.content.Intent)

setShortcut

MenuItem setShortcut(char numericChar,
                     char alphaChar)
Change both the numeric and alphabetic shortcut associated with this item. Note that the shortcut will be triggered when the key that generates the given character is pressed alone or along with with the alt key. Also note that case is not significant and that alphabetic shortcut characters will be displayed in lower case.

See Menu for the menu types that support shortcuts.

Parameters:
numericChar - The numeric shortcut key. This is the shortcut when using a numeric (e.g., 12-key) keyboard.
alphaChar - The alphabetic shortcut key. This is the shortcut when using a keyboard with alphabetic keys.
Returns:
This Item so additional setters can be called.

setNumericShortcut

MenuItem setNumericShortcut(char numericChar)
Change the numeric shortcut associated with this item.

See Menu for the menu types that support shortcuts.

Parameters:
numericChar - The numeric shortcut key. This is the shortcut when using a 12-key (numeric) keyboard.
Returns:
This Item so additional setters can be called.

getNumericShortcut

char getNumericShortcut()
Return the char for this menu item's numeric (12-key) shortcut.

Returns:
Numeric character to use as a shortcut.

setAlphabeticShortcut

MenuItem setAlphabeticShortcut(char alphaChar)
Change the alphabetic shortcut associated with this item. The shortcut will be triggered when the key that generates the given character is pressed alone or along with with the alt key. Case is not significant and shortcut characters will be displayed in lower case. Note that menu items with the characters '\b' or '\n' as shortcuts will get triggered by the Delete key or Carriage Return key, respectively.

See Menu for the menu types that support shortcuts.

Parameters:
alphaChar - The alphabetic shortcut key. This is the shortcut when using a keyboard with alphabetic keys.
Returns:
This Item so additional setters can be called.

getAlphabeticShortcut

char getAlphabeticShortcut()
Return the char for this menu item's alphabetic shortcut.

Returns:
Alphabetic character to use as a shortcut.

setCheckable

MenuItem setCheckable(boolean checkable)
Control whether this item can display a check mark. Setting this does not actually display a check mark (see setChecked(boolean) for that); rather, it ensures there is room in the item in which to display a check mark.

See Menu for the menu types that support check marks.

Parameters:
checkable - Set to true to allow a check mark, false to disallow. The default is false.
Returns:
This Item so additional setters can be called.
See Also:
setChecked(boolean), isCheckable(), Menu.setGroupCheckable(int, boolean, boolean)

isCheckable

boolean isCheckable()
Return whether the item can currently display a check mark.

Returns:
If a check mark can be displayed, returns true.
See Also:
setCheckable(boolean)

setChecked

MenuItem setChecked(boolean checked)
Control whether this item is shown with a check mark. Note that you must first have enabled checking with setCheckable(boolean) or else the check mark will not appear. If this item is a member of a group that contains mutually-exclusive items (set via Menu.setGroupCheckable(int, boolean, boolean), the other items in the group will be unchecked.

See Menu for the menu types that support check marks.

Parameters:
checked - Set to true to display a check mark, false to hide it. The default value is false.
Returns:
This Item so additional setters can be called.
See Also:
setCheckable(boolean), isChecked(), Menu.setGroupCheckable(int, boolean, boolean)

isChecked

boolean isChecked()
Return whether the item is currently displaying a check mark.

Returns:
If a check mark is displayed, returns true.
See Also:
setChecked(boolean)

setVisible

MenuItem setVisible(boolean visible)
Sets the visibility of the menu item. Even if a menu item is not visible, it may still be invoked via its shortcut (to completely disable an item, set it to invisible and disabled).

Parameters:
visible - If true then the item will be visible; if false it is hidden.
Returns:
This Item so additional setters can be called.

isVisible

boolean isVisible()
Return the visibility of the menu item.

Returns:
If true the item is visible; else it is hidden.

setEnabled

MenuItem setEnabled(boolean enabled)
Sets whether the menu item is enabled. Disabling a menu item will not allow it to be invoked via its shortcut. The menu item will still be visible.

Parameters:
enabled - If true then the item will be invokable; if false it is won't be invokable.
Returns:
This Item so additional setters can be called.

isEnabled

boolean isEnabled()
Return the enabled state of the menu item.

Returns:
If true the item is enabled and hence invokable; else it is not.

hasSubMenu

boolean hasSubMenu()
Check whether this item has an associated sub-menu. I.e. it is a sub-menu of another menu.

Returns:
If true this item has a menu; else it is a normal item.

getSubMenu

SubMenu getSubMenu()
Get the sub-menu to be invoked when this item is selected, if it has one. See hasSubMenu().

Returns:
The associated menu if there is one, else null

setOnMenuItemClickListener

MenuItem setOnMenuItemClickListener(MenuItem.OnMenuItemClickListener menuItemClickListener)
Set a custom listener for invocation of this menu item. In most situations, it is more efficient and easier to use Activity.onOptionsItemSelected(MenuItem) or Activity.onContextItemSelected(MenuItem).

Parameters:
menuItemClickListener - The object to receive invokations.
Returns:
This Item so additional setters can be called.
See Also:
Activity.onOptionsItemSelected(MenuItem), Activity.onContextItemSelected(MenuItem)

getMenuInfo

ContextMenu.ContextMenuInfo getMenuInfo()
Gets the extra information linked to this menu item. This extra information is set by the View that added this menu item to the menu.

Returns:
The extra information linked to the View that added this menu item to the menu. This can be null.
See Also:
View.OnCreateContextMenuListener

Build 1.0_r1(from source)

Please submit a feedback, bug or feature