下面列出了android.widget.ExpandableListView.ExpandableListContextMenuInfo#android.widget.AdapterView.AdapterContextMenuInfo 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo menuInfo =
(AdapterContextMenuInfo) item.getMenuInfo();
// TODO: Implement this method
if (item.getItemId() == 0) {
//修改持续时间
showEditTextDialog(HCActivity.this, "设置该图持续的时间(秒)", menuInfo.position);
} else if (item.getItemId() == 1) {
//移除项
items.remove(menuInfo.position);
adapter.notifyDataSetChanged();
showToast("移除成功");
}
return super.onOptionsItemSelected(item);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo menuInfo =
(AdapterContextMenuInfo) item.getMenuInfo();
// TODO: Implement this method
if (item.getItemId() == 0) {
//预览
Intent intent = new Intent("android.intent.action.VIEW");
intent.addCategory("android.intent.category.DEFAULT");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Uri uri = Uri.fromFile(new File(curpath + "/" + files_name.get(menuInfo.position - dirs_name.size())));
intent.setDataAndType(uri, "image/*");
startActivity(intent);
}
return super.onOptionsItemSelected(item);
}
@Override
public boolean onContextItemSelected(MenuItem item)
{
AdapterContextMenuInfo menuInfo =
(AdapterContextMenuInfo) item.getMenuInfo();
// TODO: Implement this method
if (item.getItemId() == 0)
{
//修改持续时间
showEditTextDialog(HCActivity.this, "设置该图持续的时间(秒)", menuInfo.position);
}
else if (item.getItemId() == 1)
{
//移除项
items.remove(menuInfo.position);
adapter.notifyDataSetChanged();
showToast("移除成功");
}
return super.onOptionsItemSelected(item);
}
@Override
public boolean onContextItemSelected(MenuItem item)
{
AdapterContextMenuInfo menuInfo =
(AdapterContextMenuInfo) item.getMenuInfo();
// TODO: Implement this method
if (item.getItemId() == 0)
{
//预览
Intent intent = new Intent("android.intent.action.VIEW");
intent.addCategory("android.intent.category.DEFAULT");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Uri uri = Uri.fromFile(new File(curpath + "/" + files_name.get(menuInfo.position - dirs_name.size())));
intent.setDataAndType(uri, "image/*");
startActivity(intent);
}
return super.onOptionsItemSelected(item);
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
if (!canCreateContextMenu(menu, menuInfo)) {
return;
}
menu.clear();
ViewHolder holder = (ViewHolder) ((AdapterContextMenuInfo) menuInfo).targetView.getTag();
menu.setHeaderTitle(holder.nameView.getText());
if (holder.icon != null) {
setHeaderIcon(menu, holder.icon);
}
menu.add(Menu.NONE, R.string.app_info, Menu.NONE, R.string.app_info);
updatePreventMenu(menu, holder.packageName);
if (getMainIntent(holder.packageName) != null) {
menu.add(Menu.NONE, R.string.open, Menu.NONE, R.string.open);
}
if (holder.canUninstall) {
menu.add(Menu.NONE, R.string.uninstall, Menu.NONE, R.string.uninstall);
}
if (appNotification) {
menu.add(Menu.NONE, R.string.app_notifications, Menu.NONE, R.string.app_notifications);
}
}
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
int selectedItemPosition = info.position;
listView.setItemChecked(selectedItemPosition, true); // Set the chosen item as selected
switch (item.getItemId()) {
case MENU_EDIT:
editItem(selectedItemPosition);
return true;
case MENU_DELETE:
confirmDeleteItem(selectedItemPosition);
return true;
default:
return super.onContextItemSelected(item);
}
}
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
switch (item.getItemId()) {
case MENU_EDIT:
editRule(info.position);
return true;
case MENU_DELETE:
deleteRule(info.position);
return true;
case MENU_TOGGLE:
ruleListAdapter.toggleRule(info.position);
return true;
case MENU_NOTIFICATION:
ruleListAdapter.setNotification(info.position);
default:
return super.onContextItemSelected(item);
}
}
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
switch (item.getItemId()) {
case R.id.contextMenuAdd:
controller.getPlayNow().add(controller.getSongs().get((int) info.id));
Context context = getView().getContext();
CharSequence text = getResources().getString(R.string.songsViewSongAdded);
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
return true;
case R.id.contextMenuSongsOpen:
controller.getPlayNow().clear();
controller.getPlayNow().add(controller.getSongs().get((int) info.id));
((MainActivity) getActivity()).play(0);
return true;
default:
return super.onContextItemSelected(item);
}
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
ManageAccountActivity.this.getMenuInflater().inflate(
R.menu.manageaccounts_context, menu);
AdapterContextMenuInfo acmi = (AdapterContextMenuInfo) menuInfo;
this.selectedAccount = accountList.get(acmi.position);
if (this.selectedAccount.isEnabled()) {
menu.findItem(R.id.mgmt_account_announce_pgp).setVisible(Config.supportOpenPgp());
} else {
menu.findItem(R.id.mgmt_account_reconnect).setVisible(false);
menu.findItem(R.id.mgmt_account_announce_pgp).setVisible(false);
menu.findItem(R.id.mgmt_account_publish_avatar).setVisible(false);
}
menu.setHeaderTitle(this.selectedAccount.getJid().asBareJid().toEscapedString());
}
@Override
public boolean onContextItemSelected(MenuItem item) {
if (getUserVisibleHint() && item.getMenuInfo() instanceof AdapterContextMenuInfo) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
if(info == null) // info can be null
return super.onContextItemSelected(item);
int id = item.getItemId();
if(id == R.id.audio_player_mini_remove) {
Log.d(TAG, "Context menu removing " + info.position);
if (mService != null)
mService.remove(info.position);
return true;
}
return super.onContextItemSelected(item);
} else
return false;
}
@Override
public boolean onContextItemSelected(MenuItem item) {
boolean handled = false;
boolean deleteMessage = false;
if (item.getItemId() == R.id.delete_message) {
deleteMessage = true;
handled = true;
} else if (item.getItemId() == R.id.delete_conversation) {
deleteMessage = false;
handled = true;
}
EMConversation tobeDeleteCons = adapter.getItem(((AdapterContextMenuInfo) item.getMenuInfo()).position);
// 删除此会话
EMChatManager.getInstance().deleteConversation(tobeDeleteCons.getUserName(), tobeDeleteCons.isGroup(), deleteMessage);
InviteMessgeDao inviteMessgeDao = new InviteMessgeDao(this);
inviteMessgeDao.deleteMessage(tobeDeleteCons.getUserName());
adapter.remove(tobeDeleteCons);
adapter.notifyDataSetChanged();
// 更新消息未读数
// updateUnreadLabel();
return handled ? true : super.onContextItemSelected(item);
}
@Override
public boolean onContextItemSelected(final MenuItem item) {
final AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo) item
.getMenuInfo();
final int id = item.getItemId();
final Cursor c = (Cursor) this.mCursorAdapter
.getItem(menuInfo.position);
if (c != null) {
final DirectMessage dm = DirectMessage.parse(c);
if ((dm != null) && !dm.isNull()) {
switch (id) {
case R.id.dm_copy:
doCopy(dm);
break;
case R.id.dm_delete:
doDelete(dm);
break;
default:
break;
}
}
}
return true;
// return super.onContextItemSelected(item);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
if (item.getItemId() == 1) {
Callable callable = new Callable() {
@Override
public Object call() throws Exception {
portfolioRepository.updateStock(mStockSymbol);
refreshView();
return new Object();
}
};
DialogTools.alertWithCallback(this, "Confirm Delete",
"Clear portfolio info for " + mStockSymbol + "?", "Delete", "Cancel",
callable, null);
} else if (item.getItemId() == 0) {
AdapterContextMenuInfo menuInfo = ((AdapterView.AdapterContextMenuInfo) item.getMenuInfo());
showPortfolioItemEdit(mPortfolioListView, menuInfo.position);
}
return super.onContextItemSelected(item);
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
PinInfo selectedUser = users[(int) info.id];
getMenuInflater().inflate(R.menu.account_list_context, menu);
menu.setHeaderTitle(selectedUser.getIndex().getStrippedName());
if (!isRenameAccountAvailableSupported(selectedUser)) {
menu.removeItem(R.id.rename);
}
if (!isCheckAccountKeyValueSupported(selectedUser)) {
menu.removeItem(R.id.check_code);
}
mostRecentContextMenu = menu;
}
@Override
public boolean onContextItemSelected(MenuItem item) {
/*
* Contiene información sobre el elemento del menú contextual
* sobre el que se ha pulsado
*/
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
switch (item.getItemId()) {
case R.id.ctx_eliminar:
eliminarContacto(info);
return true;
default:
return super.onContextItemSelected(item);
}
}
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
int position = info.position;
String newspaper = cellList.get(position).getNewspaperImage();
String category = cellList.get(position).getCategoryTitle();
switch (item.getItemId()) {
case R.id.edit:
activityCallback.showEditCellDialog(position, newspaper, category, cellList, adapter);
return true;
case R.id.delete:
UserPrefUtil.getInstance(getActivity()).deleteUserPref(cellList.get(position));
cellList.remove(position);
adapter.notifyDataSetChanged();
return true;
default:
return super.onContextItemSelected(item);
}
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
ManageAccountActivity.this.getMenuInflater().inflate(
R.menu.manageaccounts_context, menu);
AdapterContextMenuInfo acmi = (AdapterContextMenuInfo) menuInfo;
this.selectedAccount = accountList.get(acmi.position);
if (this.selectedAccount.isEnabled()) {
menu.findItem(R.id.mgmt_account_enable).setVisible(false);
menu.findItem(R.id.mgmt_account_announce_pgp).setVisible(Config.supportOpenPgp());
} else {
menu.findItem(R.id.mgmt_account_disable).setVisible(false);
menu.findItem(R.id.mgmt_account_announce_pgp).setVisible(false);
menu.findItem(R.id.mgmt_account_publish_avatar).setVisible(false);
}
menu.setHeaderTitle(this.selectedAccount.getJid().asBareJid().toEscapedString());
}
@Override
public boolean onContextItemSelected(MenuItem menuItem) {
ContextMenuInfo menuInfo = menuItem.getMenuInfo();
if (menuInfo instanceof AdapterContextMenuInfo) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
if (info.position < mAdapter.getCount()) {
PlaylistItem item = mAdapter.getItem(info.position);
switch (menuItem.getItemId()) {
case R.id.playlist_context_play:
selectItem(item);
return true;
case R.id.playlist_context_dequeue:
removeItem(item, info.position);
return true;
case R.id.playlist_context_search:
searchForItem(item);
return true;
}
}
}
return super.onContextItemSelected(menuItem);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item
.getMenuInfo();
switch (item.getItemId()) {
case R.id.itemLoad:
loadSession(info.id);
return true;
case R.id.itemDelete:
deleteSession(info.id);
return true;
// case R.id.itemExport:
// exportSession(info.id);
// return true;
default:
return false;
}
}
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo menuInfo =
(AdapterContextMenuInfo) item.getMenuInfo();
// TODO: Implement this method
if (item.getItemId() == 0) {
//移除项
items.remove(menuInfo.position);
adapter.notifyDataSetChanged();
showToast("移除成功");
}
return super.onOptionsItemSelected(item);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
if (info == null || info.targetView == null) {
return false;
}
String sipUri = chatList.getAdapter().getItem(info.position).toString();
LinphoneActivity.instance().removeFromChatList(sipUri);
mConversations = LinphoneActivity.instance().getChatList();
hideAndDisplayMessageIfNoChat();
return true;
}
@Override
public boolean onContextItemSelected(MenuItem item)
{
AdapterContextMenuInfo menuInfo =
(AdapterContextMenuInfo) item.getMenuInfo();
// TODO: Implement this method
if (item.getItemId() == 0)
{
//移除项
items.remove(menuInfo.position);
adapter.notifyDataSetChanged();
showToast("移除成功");
}
return super.onOptionsItemSelected(item);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
Playlist selected = controller.getSelectedPlaylists().get((int) info.id);
String urlString = controller.getServer().getHost() + "/server/xml.server.php?action=playlist_songs&auth="
+ controller.getServer().getAuthKey() + "&filter=" + String.valueOf(selected.getId());
Log.d("url", urlString);
switch (item.getItemId()) {
case R.id.contextMenuAdd:
controller.parsePlaylistSongs(urlString, controller.getPlayNow());
Context context = getView().getContext();
CharSequence text = getResources().getString(R.string.playlistsViewPlaylistAdded);
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
return true;
case R.id.contextMenuOpen:
controller.getSelectedSongs().clear();
controller.parsePlaylistSongs(urlString, controller.getSelectedSongs());
// Create new fragment and transaction
SelectedSongsView newFragment = new SelectedSongsView();
FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();
// Replace whatever is in the fragment_container view with this fragment,
// and add the transaction to the back stack
transaction.replace(R.id.content_frame, newFragment);
transaction.addToBackStack(null);
// Commit the transaction
transaction.commit();
return true;
default:
return super.onContextItemSelected(item);
}
}
private void setListViewContextMenuWithDel_Resume() {
lvMang.setOnCreateContextMenuListener(new OnCreateContextMenuListener() {
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
intCurrDataPos = ((AdapterContextMenuInfo) menuInfo).position;
menu.add(0, 0, 0, "删除");
menu.add(0, 1, 1, "恢复所有已暂停车次");
}
});
}
@Override
public boolean onContextItemSelected(MenuItem item) {
switch (item.getItemId()) {
case DELETE_ID:
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item
.getMenuInfo();
Uri uri = Uri.parse(MyTodoContentProvider.CONTENT_URI + "/"
+ info.id);
getContentResolver().delete(uri, null, null);
fillData();
return true;
}
return super.onContextItemSelected(item);
}
@Override
public boolean onContextItemSelected(@NonNull MenuItem item) {
if (current instanceof Form) {
((Form) current).contextMenuItemSelected(item);
} else if (current instanceof List) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
((List) current).contextMenuItemSelected(item, info.position);
}
return super.onContextItemSelected(item);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
if (mActivity == null || item == null) {
return false;
}
ViewHolder holder = (ViewHolder) ((AdapterContextMenuInfo) item.getMenuInfo()).targetView.getTag();
return onContextItemSelected(holder, holder.packageName, item.getItemId());
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
// TODO(acase): Create ViewRule option and corresponding Activity that doesn't provide "Editing"
menu.setHeaderTitle(ruleListAdapter.getItem(info.position).getName());
menu.add(ContextMenu.NONE, MENU_TOGGLE, ContextMenu.NONE, R.string.toggle_rule);
menu.add(ContextMenu.NONE, MENU_EDIT, ContextMenu.NONE, R.string.edit_rule);
menu.add(ContextMenu.NONE, MENU_DELETE, ContextMenu.NONE, R.string.delete_rule);
menu.add(ContextMenu.NONE, MENU_NOTIFICATION, ContextMenu.NONE,
getNotificationTitle(info.position));
}
/**
* {@inhericDoc}
*/
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
boolean matched = onFileActionChosen(item.getItemId(), ((AdapterContextMenuInfo) item.getMenuInfo()).position);
if (!matched) {
return super.onContextItemSelected(item);
} else {
return matched;
}
}
/**
* {@inhericDoc}
*/
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
boolean matched = onFileActionChosen(item.getItemId(), ((AdapterContextMenuInfo) item.getMenuInfo()).position);
if (!matched) {
return super.onContextItemSelected(item);
} else {
return matched;
}
}