FileDocCategorySizeDatePackage
ListMenuPresenter.javaAPI DocAndroid 5.1 API8540Thu Mar 12 22:22:10 GMT 2015com.android.internal.view.menu

ListMenuPresenter

public class ListMenuPresenter extends Object implements MenuPresenter, AdapterView.OnItemClickListener
MenuPresenter for list-style menus.

Fields Summary
private static final String
TAG
android.content.Context
mContext
android.view.LayoutInflater
mInflater
MenuBuilder
mMenu
ExpandedMenuView
mMenuView
private int
mItemIndexOffset
int
mThemeRes
int
mItemLayoutRes
private Callback
mCallback
MenuAdapter
mAdapter
private int
mId
public static final String
VIEWS_TAG
Constructors Summary
public ListMenuPresenter(android.content.Context context, int itemLayoutRes)
Construct a new ListMenuPresenter.

param
context Context to use for theming. This will supersede the context provided to initForMenu when this presenter is added.
param
itemLayoutRes Layout resource for individual item views.


                                                        
         
        this(itemLayoutRes, 0);
        mContext = context;
        mInflater = LayoutInflater.from(mContext);
    
public ListMenuPresenter(int itemLayoutRes, int themeRes)
Construct a new ListMenuPresenter.

param
itemLayoutRes Layout resource for individual item views.
param
themeRes Resource ID of a theme to use for views.

        mItemLayoutRes = itemLayoutRes;
        mThemeRes = themeRes;
    
Methods Summary
public booleancollapseItemActionView(MenuBuilder menu, MenuItemImpl item)

        return false;
    
public booleanexpandItemActionView(MenuBuilder menu, MenuItemImpl item)

        return false;
    
public booleanflagActionItems()

        return false;
    
public android.widget.ListAdaptergetAdapter()
Call this instead of getMenuView if you want to manage your own ListView. For proper operation, the ListView hosting this adapter should add this presenter as an OnItemClickListener.

return
A ListAdapter containing the items in the menu.

        if (mAdapter == null) {
            mAdapter = new MenuAdapter();
        }
        return mAdapter;
    
public intgetId()

        return mId;
    
intgetItemIndexOffset()

        return mItemIndexOffset;
    
public MenuViewgetMenuView(android.view.ViewGroup root)

        if (mMenuView == null) {
            mMenuView = (ExpandedMenuView) mInflater.inflate(
                    com.android.internal.R.layout.expanded_menu_layout, root, false);
            if (mAdapter == null) {
                mAdapter = new MenuAdapter();
            }
            mMenuView.setAdapter(mAdapter);
            mMenuView.setOnItemClickListener(this);
        }
        return mMenuView;
    
public voidinitForMenu(android.content.Context context, MenuBuilder menu)

        if (mThemeRes != 0) {
            mContext = new ContextThemeWrapper(context, mThemeRes);
            mInflater = LayoutInflater.from(mContext);
        } else if (mContext != null) {
            mContext = context;
            if (mInflater == null) {
                mInflater = LayoutInflater.from(mContext);
            }
        }
        mMenu = menu;
        if (mAdapter != null) {
            mAdapter.notifyDataSetChanged();
        }
    
public voidonCloseMenu(MenuBuilder menu, boolean allMenusAreClosing)

        if (mCallback != null) {
            mCallback.onCloseMenu(menu, allMenusAreClosing);
        }
    
public voidonItemClick(android.widget.AdapterView parent, android.view.View view, int position, long id)

        mMenu.performItemAction(mAdapter.getItem(position), this, 0);
    
public voidonRestoreInstanceState(android.os.Parcelable state)

        restoreHierarchyState((Bundle) state);
    
public android.os.ParcelableonSaveInstanceState()

        if (mMenuView == null) {
            return null;
        }

        Bundle state = new Bundle();
        saveHierarchyState(state);
        return state;
    
public booleanonSubMenuSelected(SubMenuBuilder subMenu)

        if (!subMenu.hasVisibleItems()) return false;

        // The window manager will give us a token.
        new MenuDialogHelper(subMenu).show(null);
        if (mCallback != null) {
            mCallback.onOpenSubMenu(subMenu);
        }
        return true;
    
public voidrestoreHierarchyState(android.os.Bundle inState)

        SparseArray<Parcelable> viewStates = inState.getSparseParcelableArray(VIEWS_TAG);
        if (viewStates != null) {
            ((View) mMenuView).restoreHierarchyState(viewStates);
        }
    
public voidsaveHierarchyState(android.os.Bundle outState)

        SparseArray<Parcelable> viewStates = new SparseArray<Parcelable>();
        if (mMenuView != null) {
            ((View) mMenuView).saveHierarchyState(viewStates);
        }
        outState.putSparseParcelableArray(VIEWS_TAG, viewStates);
    
public voidsetCallback(Callback cb)

        mCallback = cb;
    
public voidsetId(int id)

        mId = id;
    
public voidsetItemIndexOffset(int offset)

        mItemIndexOffset = offset;
        if (mMenuView != null) {
            updateMenuView(false);
        }
    
public voidupdateMenuView(boolean cleared)

        if (mAdapter != null) mAdapter.notifyDataSetChanged();