當前位置: 首頁>>代碼示例>>Java>>正文


Java Menu.removeGroup方法代碼示例

本文整理匯總了Java中android.view.Menu.removeGroup方法的典型用法代碼示例。如果您正苦於以下問題:Java Menu.removeGroup方法的具體用法?Java Menu.removeGroup怎麽用?Java Menu.removeGroup使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.view.Menu的用法示例。


在下文中一共展示了Menu.removeGroup方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onPrepareOptionsMenu

import android.view.Menu; //導入方法依賴的package包/類
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);

    // The paste menu item is enabled if there is data on the clipboard.
    ClipboardManager clipboard = (ClipboardManager)
            getSystemService(Context.CLIPBOARD_SERVICE);


    MenuItem mPasteItem = menu.findItem(R.id.menu_paste);

    // If the clipboard contains an item, enables the Paste option on the menu.
    if (clipboard.hasPrimaryClip()) {
        mPasteItem.setEnabled(true);
    } else {
        // If the clipboard is empty, disables the menu's Paste option.
        mPasteItem.setEnabled(false);
    }

    // Gets the number of notes currently being displayed.
    final boolean haveItems = getListAdapter().getCount() > 0;

    // If there are any notes in the list (which implies that one of
    // them is selected), then we need to generate the actions that
    // can be performed on the current selection.  This will be a combination
    // of our own specific actions along with any extensions that can be
    // found.
    if (haveItems) {

        // This is the selected item.
        Uri uri = ContentUris.withAppendedId(getIntent().getData(), getSelectedItemId());

        // Creates an array of Intents with one element. This will be used to send an Intent
        // based on the selected menu item.
        Intent[] specifics = new Intent[1];

        // Sets the Intent in the array to be an EDIT action on the URI of the selected note.
        specifics[0] = new Intent(Intent.ACTION_EDIT, uri);

        // Creates an array of menu items with one element. This will contain the EDIT option.
        MenuItem[] items = new MenuItem[1];

        // Creates an Intent with no specific action, using the URI of the selected note.
        Intent intent = new Intent(null, uri);

        /* Adds the category ALTERNATIVE to the Intent, with the note ID URI as its
         * data. This prepares the Intent as a place to group alternative options in the
         * menu.
         */
        intent.addCategory(Intent.CATEGORY_ALTERNATIVE);

        /*
         * Add alternatives to the menu
         */
        menu.addIntentOptions(
            Menu.CATEGORY_ALTERNATIVE,  // Add the Intents as options in the alternatives group.
            Menu.NONE,                  // A unique item ID is not required.
            Menu.NONE,                  // The alternatives don't need to be in order.
            null,                       // The caller's name is not excluded from the group.
            specifics,                  // These specific options must appear first.
            intent,                     // These Intent objects map to the options in specifics.
            Menu.NONE,                  // No flags are required.
            items                       // The menu items generated from the specifics-to-
                                        // Intents mapping
        );
            // If the Edit menu item exists, adds shortcuts for it.
            if (items[0] != null) {

                // Sets the Edit menu item shortcut to numeric "1", letter "e"
                items[0].setShortcut('1', 'e');
            }
        } else {
            // If the list is empty, removes any existing alternative actions from the menu
            menu.removeGroup(Menu.CATEGORY_ALTERNATIVE);
        }

    // Displays the menu
    return true;
}
 
開發者ID:sdrausty,項目名稱:buildAPKsSamples,代碼行數:80,代碼來源:NotesList.java


注:本文中的android.view.Menu.removeGroup方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。