Example usage for android.app Activity onOptionsItemSelected

List of usage examples for android.app Activity onOptionsItemSelected

Introduction

In this page you can find the example usage for android.app Activity onOptionsItemSelected.

Prototype

public boolean onOptionsItemSelected(MenuItem item) 

Source Link

Document

This hook is called whenever an item in your options menu is selected.

Usage

From source file:com.vuze.android.remote.AndroidUtilsUI.java

public static boolean popupContextMenu(final Activity activity, String title) {
    MenuBuilder menuBuilder = new MenuBuilder(activity);

    if (title != null) {
        try {//from w  w w.ja va  2s.com
            Method mSetHeaderTitle = menuBuilder.getClass().getDeclaredMethod("setHeaderTitleInt",
                    CharSequence.class);
            if (mSetHeaderTitle != null) {
                mSetHeaderTitle.setAccessible(true);
                mSetHeaderTitle.invoke(menuBuilder, title);
            }
        } catch (Throwable ignore) {
        }
    }

    if (!activity.onCreateOptionsMenu(menuBuilder)) {
        return false;
    }

    activity.onPrepareOptionsMenu(menuBuilder);

    menuBuilder.setCallback(new MenuBuilder.Callback() {
        @Override
        public boolean onMenuItemSelected(MenuBuilder menu, MenuItem item) {
            return activity.onOptionsItemSelected(item);
        }

        @Override
        public void onMenuModeChange(MenuBuilder menu) {

        }
    });

    MenuDialogHelper menuDialogHelper = new MenuDialogHelper(menuBuilder);
    menuDialogHelper.show(null);

    return true;
}