FileDocCategorySizeDatePackage
ContextMenuBuilder.javaAPI DocAndroid 1.5 API3334Wed May 06 22:41:56 BST 2009com.android.internal.view.menu

ContextMenuBuilder

public class ContextMenuBuilder extends MenuBuilder implements android.view.ContextMenu
Implementation of the {@link android.view.ContextMenu} interface.

Most clients of the menu framework will never need to touch this class. However, if the client has a window that is not a content view of a Dialog or Activity (for example, the view was added directly to the window manager) and needs to show context menus, it will use this class.

To use this class, instantiate it via {@link #ContextMenuBuilder(Context)}, and optionally populate it with any of your custom items. Finally, call {@link #show(View, IBinder)} which will populate the menu with a view's context menu items and show the context menu.

Fields Summary
Constructors Summary
public ContextMenuBuilder(android.content.Context context)

        super(context);
    
Methods Summary
public android.view.ContextMenusetHeaderIcon(android.graphics.drawable.Drawable icon)

        return (ContextMenu) super.setHeaderIconInt(icon);
    
public android.view.ContextMenusetHeaderIcon(int iconRes)

        return (ContextMenu) super.setHeaderIconInt(iconRes);
    
public android.view.ContextMenusetHeaderTitle(java.lang.CharSequence title)

        return (ContextMenu) super.setHeaderTitleInt(title);
    
public android.view.ContextMenusetHeaderTitle(int titleRes)

        return (ContextMenu) super.setHeaderTitleInt(titleRes);
    
public android.view.ContextMenusetHeaderView(android.view.View view)

        return (ContextMenu) super.setHeaderViewInt(view);
    
public MenuDialogHelpershow(android.view.View originalView, android.os.IBinder token)
Shows this context menu, allowing the optional original view (and its ancestors) to add items.

param
originalView Optional, the original view that triggered the context menu.
param
token Optional, the window token that should be set on the context menu's window.
return
If the context menu was shown, the {@link MenuDialogHelper} for dismissing it. Otherwise, null.

        if (originalView != null) {
            // Let relevant views and their populate context listeners populate
            // the context menu
            originalView.createContextMenu(this);
        }

        if (getVisibleItems().size() > 0) {
            EventLog.writeEvent(50001, 1);
            
            MenuDialogHelper helper = new MenuDialogHelper(this); 
            helper.show(token);
            
            return helper;
        }
        
        return null;