ContextMenu


public interface ContextMenu
implements Menu

android.view.ContextMenu


Extension of Menu for context menus providing functionality to modify the header of the context menu.

Context menus do not support item shortcuts and item icons.

To show a context menu on long click, most clients will want to call Activity.registerForContextMenu and override Activity.onCreateContextMenu.

Developer Guides

For information about creating menus, read the Menus developer guide.

Summary

Nested classes

interface ContextMenu.ContextMenuInfo

Additional information regarding the creation of the context menu. 

Inherited constants

int CATEGORY_ALTERNATIVE

Category code for the order integer for items/groups that are alternative actions on the data that is currently displayed -- or/add this with your base value.

int CATEGORY_CONTAINER

Category code for the order integer for items/groups that are part of a container -- or/add this with your base value.

int CATEGORY_SECONDARY

Category code for the order integer for items/groups that are user-supplied secondary (infrequently used) options -- or/add this with your base value.

int CATEGORY_SYSTEM

Category code for the order integer for items/groups that are provided by the system -- or/add this with your base value.

int FIRST

First value for group and item identifier integers.

int FLAG_ALWAYS_PERFORM_CLOSE

Flag for performShortcut(int, android.view.KeyEvent, int): if set, always close the menu after executing the shortcut.

int FLAG_APPEND_TO_GROUP

Flag for addIntentOptions(int, int, int, ComponentName, Intent, Intent, int, MenuItem): if set, do not automatically remove any existing menu items in the same group.

int FLAG_PERFORM_NO_CLOSE

Flag for performShortcut(int, KeyEvent, int): if set, do not close the menu after executing the shortcut.

int NONE

Value to use for group and item identifier integers when you don't care about them.

int SUPPORTED_MODIFIERS_MASK

A mask of all supported modifiers for MenuItem's keyboard shortcuts

Public methods

abstract void clearHeader()

Clears the header of the context menu.

abstract ContextMenu setHeaderIcon(int iconRes)

Sets the context menu header's icon to the icon given in iconRes resource id.

abstract ContextMenu setHeaderIcon(Drawable icon)

Sets the context menu header's icon to the icon given in icon Drawable.

abstract ContextMenu setHeaderTitle(int titleRes)

Sets the context menu header's title to the title given in titleRes resource identifier.

abstract ContextMenu setHeaderTitle(CharSequence title)

Sets the context menu header's title to the title given in title.

abstract ContextMenu setHeaderView(View view)

Sets the header of the context menu to the View given in view.

Inherited methods

abstract MenuItem add(int groupId, int itemId, int order, CharSequence title)

Add a new item to the menu.

abstract MenuItem add(int titleRes)

Add a new item to the menu.

abstract MenuItem add(CharSequence title)

Add a new item to the menu.

abstract MenuItem add(int groupId, int itemId, int order, int titleRes)

Variation on add(int, int, int, java.lang.CharSequence) that takes a string resource identifier instead of the string itself.

abstract int addIntentOptions(int groupId, int itemId, int order, ComponentName caller, Intent[] specifics, Intent intent, int flags, MenuItem[] outSpecificItems)

Add a group of menu items corresponding to actions that can be performed for a particular Intent.

abstract SubMenu addSubMenu(CharSequence title)

Add a new sub-menu to the menu.

abstract SubMenu addSubMenu(int groupId, int itemId, int order, int titleRes)

Variation on addSubMenu(int, int, int, java.lang.CharSequence) that takes a string resource identifier for the title instead of the string itself.

abstract SubMenu addSubMenu(int groupId, int itemId, int order, CharSequence title)

Add a new sub-menu to the menu.

abstract SubMenu addSubMenu(int titleRes)

Add a new sub-menu to the menu.

abstract void clear()

Remove all existing items from the menu, leaving it empty as if it had just been created.

abstract void close()

Closes the menu, if open.

abstract MenuItem findItem(int id)

Return the menu item with a particular identifier.

abstract MenuItem getItem(int index)

Gets the menu item at the given index.

abstract boolean hasVisibleItems()

Return whether the menu currently has item items that are visible.

abstract boolean isShortcutKey(int keyCode, KeyEvent event)

Is a keypress one of the defined shortcut keys for this window.

abstract boolean performIdentifierAction(int id, int flags)

Execute the menu item action associated with the given menu identifier.

abstract boolean performShortcut(int keyCode, KeyEvent event, int flags)

Execute the menu item action associated with the given shortcut character.

abstract void removeGroup(int groupId)

Remove all items in the given group.

abstract void removeItem(int id)

Remove the item with the given identifier.

abstract void setGroupCheckable(int group, boolean checkable, boolean exclusive)

Control whether a particular group of items can show a check mark.

default void setGroupDividerEnabled(boolean groupDividerEnabled)

Enable or disable the group dividers.

abstract void setGroupEnabled(int group, boolean enabled)

Enable or disable all menu items that are in the given group.

abstract void setGroupVisible(int group, boolean visible)

Show or hide all menu items that are in the given group.

abstract void setQwertyMode(boolean isQwerty)

Control whether the menu should be running in qwerty mode (alphabetic shortcuts) or 12-key mode (numeric shortcuts).

abstract int size()

Get the number of items in the menu.

Public methods

clearHeader

Added in API level 1
public abstract void clearHeader ()

Clears the header of the context menu.

setHeaderIcon

Added in API level 1
public abstract ContextMenu setHeaderIcon (int iconRes)

Sets the context menu header's icon to the icon given in iconRes resource id.

Parameters
iconRes int: The resource identifier used for the icon.

Returns
ContextMenu This ContextMenu so additional setters can be called.

setHeaderIcon

Added in API level 1
public abstract ContextMenu setHeaderIcon (Drawable icon)

Sets the context menu header's icon to the icon given in icon Drawable.

Parameters
icon Drawable: The Drawable used for the icon.

Returns
ContextMenu This ContextMenu so additional setters can be called.

setHeaderTitle

Added in API level 1
public abstract ContextMenu setHeaderTitle (int titleRes)

Sets the context menu header's title to the title given in titleRes resource identifier.

Parameters
titleRes int: The string resource identifier used for the title.

Returns
ContextMenu This ContextMenu so additional setters can be called.

setHeaderTitle

Added in API level 1
public abstract ContextMenu setHeaderTitle (CharSequence title)

Sets the context menu header's title to the title given in title.

Parameters
title CharSequence: The character sequence used for the title.

Returns
ContextMenu This ContextMenu so additional setters can be called.

setHeaderView

Added in API level 1
public abstract ContextMenu setHeaderView (View view)

Sets the header of the context menu to the View given in view. This replaces the header title and icon (and those replace this).

Parameters
view View: The View used for the header.

Returns
ContextMenu This ContextMenu so additional setters can be called.