本文整理汇总了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);
}
示例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);
}