English | Site Directory

Android - An Open Handset Alliance Project

android.view
public static interface

android.view.Menu.Item

android.view.Menu.Item

Interface for direct access to a previously created menu item.

An Item is returned by calling one of the Menu.add() methods. A menu item also supports checkmarks by setting its setCheckable() property.

Summary

Public Methods

        int  getGroup()
Return the ordering group of this menu item.
        Drawable  getIcon()
Returns the icon for this item as a Drawable (getting it from resources if it hasn't been loaded before).
        int  getId()
Return the identifier for this menu item.
        Intent  getIntent()
Return the Intent associated with this item.
        Object  getMenuInfo()
Gets the extra information linked to this menu item.
        char  getShortcutAlphabeticChar()
Return the char for this menu item's alphabetic shortcut.
        char  getShortcutNumericChar()
Return the char for this menu item's numeric (12-key) shortcut.
        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  isShown()
Return the shown state of the menu item.
        void  setAlphabeticShortcut(char alphaChar)
Change the alphabetic shortcut associated with this item.
        void  setCheckable(boolean checkable)
Control whether this item can display a check mark.
        void  setChecked(boolean checked)
Control whether this item is shown with a check mark.
        void  setClickListener(OnClickListener clickListener)
Set a custom listener for invokation of this menu item.
        void  setIcon(Drawable icon)
Change the icon associated with this item.
        void  setIcon(int iconRes)
Change the icon associated with this item.
        void  setIntent(Intent intent)
Change the Intent associated with this item.
        void  setNumericShortcut(char numericChar)
Change the numeric shortcut associated with this item.
        void  setSelectionListener(OnSelectionListener selectionListener)
Set a custom listener for selection changes of this menu item
        void  setShortcut(char numericChar, char alphaChar)
Change both the numeric and alphabetic shortcut associated with this item.
        void  setShown(boolean shown)
Sets the shown state of the menu item.
        void  setTitle(CharSequence title)
Change the title associated with this item.
        void  setTitleCondensed(CharSequence title)
Change the condensed title associated with this item.

Details

Public Methods

public int getGroup()

Return the ordering group of this menu item. The group can not be changed after the menu is created.

Returns

  • int The menu's ordering group.

public Drawable getIcon()

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

Returns

  • Drawable The icon as a Drawable.

public int getId()

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

Returns

  • int The menu's identifier.

public 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

public Object 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.

public char getShortcutAlphabeticChar()

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

Returns

  • char Alphabetic character to use as a shortcut.

public char getShortcutNumericChar()

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

Returns

  • char Numeric character to use as a shortcut.

public SubMenu getSubMenu()

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

Returns

  • SubMenu The associated menu if there is one, else null

public CharSequence getTitle()

Retrieve the current title of the item.

Returns

  • CharSequence The title.

public CharSequence getTitleCondensed()

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

Returns

  • CharSequence The condensed title, if it exists. Otherwise the normal title.

public boolean hasSubMenu()

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

Returns

  • boolean If true this item has a menu; else it is a normal item.

public boolean isCheckable()

Return whether the item can currently display a check mark.

Returns

  • If a check mark can be displayed, returns true.

public boolean isChecked()

Return whether the item is currently displaying a check mark.

Returns

  • If a check mark is displayed, returns true.

public boolean isShown()

Return the shown state of the menu item.

Returns

  • boolean If true the item is shown; else it is hidden.

public void 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.

Parameters

alphaChar The alphabetic shortcut key. This is the shortcut when using a keyboard with alphabetic keys.

public void 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.

Parameters

checkable Set to true to allow a check mark, false to disallow. The default is false.

public void 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 setGroupCheckable(int, boolean, boolean), the other items in the group will be unchecked.

Parameters

checked Set to true to display a check mark, false to hide it. The default value is false.

public void setClickListener(OnClickListener clickListener)

Set a custom listener for invokation of this menu item.

Parameters

clickListener The object to receive invokations.

public void 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.

Parameters

icon The new icon (as a Drawable) to be displayed.

public void 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. 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.

public void 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 startActivity(Intent) with the given Intent.

Note that setIntent() can not be used with the versions of add(int, int, int) that take a Runnable, because 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.

See Also

public void setNumericShortcut(char numericChar)

Change the numeric shortcut associated with this item.

Parameters

numericChar The numeric shortcut key. This is the shortcut when using a 12-key (numeric) keyboard.

public void setSelectionListener(OnSelectionListener selectionListener)

Set a custom listener for selection changes of this menu item

Parameters

selectionListener The object to receive selection change information.

public void 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.

Parameters

numericChar The numeric shortcut key. This is the shortcut when using a 12-key (numeric) keyboard.
alphaChar The alphabetic shortcut key. This is the shortcut when using a keyboard with alphabetic keys.

public void setShown(boolean shown)

Sets the shown state of the menu item. When an item is not shown, it is not visible to the user and can not be selected.

Parameters

shown If true then the item will be shown; if false it is hidden.

public void setTitle(CharSequence title)

Change the title associated with this item.

Parameters

title The new text to be displayed.

public void 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 for a menu item's view.

Parameters

title The new text to be displayed as the condensed title.
Build m5-rc15g - 14 May 2008 12:50