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


Java ContextMenu.addIntentOptions方法代碼示例

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


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

示例1: onCreateContextMenu

import android.view.ContextMenu; //導入方法依賴的package包/類
@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
    AdapterView.AdapterContextMenuInfo info;
    try {
         info = (AdapterView.AdapterContextMenuInfo) menuInfo;
    } catch (ClassCastException e) {
        Log.e(TAG, "bad menuInfo", e);
        return;
    }

    Cursor cursor = (Cursor) getListAdapter().getItem(info.position);
    if (cursor == null) {
        // For some reason the requested item isn't available, do nothing
        return;
    }

    // Inflate menu from XML resource
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.list_context_menu, menu);
    
    // Set the context menu header
    menu.setHeaderTitle(cursor.getString(COLUMN_INDEX_TITLE));
    
    // Append to the
    // menu items for any other activities that can do stuff with it
    // as well.  This does a query on the system for any activities that
    // implement the ALTERNATIVE_ACTION for our data, adding a menu item
    // for each one that is found.
    Intent intent = new Intent(null, Uri.withAppendedPath(getIntent().getData(), 
                                    Integer.toString((int) info.id) ));
    intent.addCategory(Intent.CATEGORY_ALTERNATIVE);
    menu.addIntentOptions(Menu.CATEGORY_ALTERNATIVE, 0, 0,
            new ComponentName(this, NotesList.class), null, intent, 0, null);
}
 
開發者ID:firebase,項目名稱:firebase-testlab-instr-lib,代碼行數:35,代碼來源:NotesList.java

示例2: onCreateContextMenu

import android.view.ContextMenu; //導入方法依賴的package包/類
/**
 * This method is called when the user context-clicks a note in the list. NotesList registers
 * itself as the handler for context menus in its ListView (this is done in onCreate()).
 *
 * The only available options are COPY and DELETE.
 *
 * Context-click is equivalent to long-press.
 *
 * @param menu A ContexMenu object to which items should be added.
 * @param view The View for which the context menu is being constructed.
 * @param menuInfo Data associated with view.
 * @throws ClassCastException
 */
@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {

    // The data from the menu item.
    AdapterView.AdapterContextMenuInfo info;

    // Tries to get the position of the item in the ListView that was long-pressed.
    try {
        // Casts the incoming data object into the type for AdapterView objects.
        info = (AdapterView.AdapterContextMenuInfo) menuInfo;
    } catch (ClassCastException e) {
        // If the menu object can't be cast, logs an error.
        Log.e(TAG, "bad menuInfo", e);
        return;
    }

    /*
     * Gets the data associated with the item at the selected position. getItem() returns
     * whatever the backing adapter of the ListView has associated with the item. In NotesList,
     * the adapter associated all of the data for a note with its list item. As a result,
     * getItem() returns that data as a Cursor.
     */
    Cursor cursor = (Cursor) getListAdapter().getItem(info.position);

    // If the cursor is empty, then for some reason the adapter can't get the data from the
    // provider, so returns null to the caller.
    if (cursor == null) {
        // For some reason the requested item isn't available, do nothing
        return;
    }

    // Inflate menu from XML resource
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.list_context_menu, menu);

    // Sets the menu header to be the title of the selected note.
    menu.setHeaderTitle(cursor.getString(COLUMN_INDEX_TITLE));

    // Append to the
    // menu items for any other activities that can do stuff with it
    // as well.  This does a query on the system for any activities that
    // implement the ALTERNATIVE_ACTION for our data, adding a menu item
    // for each one that is found.
    Intent intent = new Intent(null, Uri.withAppendedPath(getIntent().getData(), 
                                    Integer.toString((int) info.id) ));
    intent.addCategory(Intent.CATEGORY_ALTERNATIVE);
    menu.addIntentOptions(Menu.CATEGORY_ALTERNATIVE, 0, 0,
            new ComponentName(this, NotesList.class), null, intent, 0, null);
}
 
開發者ID:sdrausty,項目名稱:buildAPKsSamples,代碼行數:63,代碼來源:NotesList.java


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