当前位置: 首页>>代码示例>>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;未经允许,请勿转载。