List of usage examples for android.view ContextMenu getItem
public MenuItem getItem(int index);
From source file:com.pdftron.pdf.controls.AnnotationDialogFragment.java
@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); if (v.getId() == R.id.control_annotation_listview) { AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo; AnnotationInfo item = mAnnotationListAdapter.getItem(info.position); String title = String.format(getResources().getString(R.string.controls_annotation_dialog_page), item.getPageNum());//from w ww.j ava 2 s .c o m if (item.getAuthor() != null && !item.getAuthor().isEmpty()) { title = title + " " + getResources().getString(R.string.controls_annotation_dialog_author) + " " + item.getAuthor(); } menu.setHeaderTitle(title); String[] menuItems = getResources().getStringArray(R.array.annotation_dialog_context_menu); menu.add(Menu.NONE, CONTEXT_MENU_DELETE_ITEM, CONTEXT_MENU_DELETE_ITEM, menuItems[CONTEXT_MENU_DELETE_ITEM + 1]); if (mDebug) { // Convenient for debugging menu.add(Menu.NONE, CONTEXT_MENU_DELETE_ITEM_ONPAGE, CONTEXT_MENU_DELETE_ITEM_ONPAGE, menuItems[CONTEXT_MENU_DELETE_ITEM_ONPAGE + 1]); menu.add(Menu.NONE, CONTEXT_MENU_DELETE_ALL, CONTEXT_MENU_DELETE_ALL, menuItems[CONTEXT_MENU_DELETE_ALL + 1]); } MenuItem.OnMenuItemClickListener listener = new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { onContextItemSelected(item); return true; } }; menu.getItem(CONTEXT_MENU_DELETE_ITEM).setOnMenuItemClickListener(listener); if (mDebug) { menu.getItem(CONTEXT_MENU_DELETE_ITEM_ONPAGE).setOnMenuItemClickListener(listener); menu.getItem(CONTEXT_MENU_DELETE_ALL).setOnMenuItemClickListener(listener); } } }
From source file:com.fsck.k9.activity.Accounts.java
@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); menu.setHeaderTitle(R.string.accounts_context_menu_title); AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo; BaseAccount account = mAdapter.getItem(info.position); if ((account instanceof Account) && !((Account) account).isEnabled()) { getMenuInflater().inflate(R.menu.disabled_accounts_context, menu); } else {//from w ww .j av a2 s .c om getMenuInflater().inflate(R.menu.accounts_context, menu); } if (account instanceof SearchAccount) { for (int i = 0; i < menu.size(); i++) { android.view.MenuItem item = menu.getItem(i); item.setVisible(false); } } else { EnumSet<ACCOUNT_LOCATION> accountLocation = accountLocation(account); if (accountLocation.contains(ACCOUNT_LOCATION.TOP)) { menu.findItem(R.id.move_up).setEnabled(false); } else { menu.findItem(R.id.move_up).setEnabled(true); } if (accountLocation.contains(ACCOUNT_LOCATION.BOTTOM)) { menu.findItem(R.id.move_down).setEnabled(false); } else { menu.findItem(R.id.move_down).setEnabled(true); } } }
From source file:com.bernard.beaconportal.activities.activity.MessageList.java
@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo; if (v == getListView()) { if (info.position > mAdapter_Accounts.getCount() + 5) { getMenuInflater().inflate(R.menu.folder_context, menu); FolderInfoHolder folder = (FolderInfoHolder) mAdapter .getItem(info.position - (mAdapter_Accounts.getCount() + 6)); menu.setHeaderTitle(folder.displayName); } else if (info.position < mAdapter_Accounts.getCount()) { menu.setHeaderTitle(R.string.accounts_context_menu_title); if (mAdapter_Accounts == null) { Log.d("info =", "mAdapter_Accounts = null"); }/*from w w w . j av a2 s . c o m*/ BaseAccount account = (BaseAccount) mergeadapter.getItem(info.position); if ((account instanceof Account) && !((Account) account).isEnabled()) { getMenuInflater().inflate(R.menu.disabled_accounts_context, menu); } else { getMenuInflater().inflate(R.menu.accounts_context, menu); } if (account instanceof SearchAccount) { for (int i = 0; i < menu.size(); i++) { android.view.MenuItem item = menu.getItem(i); item.setVisible(false); } } else { EnumSet<ACCOUNT_LOCATION> accountLocation = accountLocation(account); if (accountLocation.contains(ACCOUNT_LOCATION.TOP)) { menu.findItem(R.id.move_up).setEnabled(false); } else { menu.findItem(R.id.move_up).setEnabled(true); } if (accountLocation.contains(ACCOUNT_LOCATION.BOTTOM)) { menu.findItem(R.id.move_down).setEnabled(false); } else { menu.findItem(R.id.move_down).setEnabled(true); } } } } }