本文整理了Java中android.view.ContextMenu
类的一些代码示例,展示了ContextMenu
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ContextMenu
类的具体详情如下:
包路径:android.view.ContextMenu
类名称:ContextMenu
暂无
代码示例来源:origin: stackoverflow.com
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
String title = ((MyItem) mAdapter.getItem(info.position)).getTitle();
menu.setHeaderTitle(title);
menu.add(Menu.NONE, MENU_CONTEXT_DELETE_ID, Menu.NONE, DELETE_TEXT);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
switch (item.getItemId()) {
case MENU_CONTEXT_DELETE_ID:
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
Log.d(TAG, "removing item pos=" + info.position);
mAdapter.remove(info.position);
return true;
default:
return super.onContextItemSelected(item);
}
}
代码示例来源:origin: k9mail/k-9
getActivity().getMenuInflater().inflate(R.menu.message_list_item_context, menu);
menu.findItem(R.id.debug_delete_locally).setVisible(BuildConfig.DEBUG);
boolean flagged = (cursor.getInt(FLAGGED_COLUMN) == 1);
menu.setHeaderTitle(subject);
menu.findItem(R.id.select).setVisible(false);
} else {
menu.findItem(R.id.deselect).setVisible(false);
menu.findItem(R.id.mark_as_read).setVisible(false);
} else {
menu.findItem(R.id.mark_as_unread).setVisible(false);
menu.findItem(R.id.flag).setVisible(false);
} else {
menu.findItem(R.id.unflag).setVisible(false);
menu.findItem(R.id.copy).setVisible(false);
menu.findItem(R.id.move).setVisible(false);
menu.findItem(R.id.archive).setVisible(false);
menu.findItem(R.id.spam).setVisible(false);
menu.findItem(R.id.archive).setVisible(false);
menu.findItem(R.id.spam).setVisible(false);
代码示例来源:origin: k9mail/k-9
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
menu.setHeaderTitle(R.string.accounts_context_menu_title);
getMenuInflater().inflate(R.menu.disabled_accounts_context, menu);
} else {
getMenuInflater().inflate(R.menu.accounts_context, menu);
for (int i = 0; i < menu.size(); i++) {
android.view.MenuItem item = menu.getItem(i);
item.setVisible(false);
EnumSet<ACCOUNT_LOCATION> accountLocation = accountLocation(account);
if (accountLocation.contains(ACCOUNT_LOCATION.TOP)) {
menu.findItem(R.id.move_up).setEnabled(false);
menu.findItem(R.id.move_up).setEnabled(true);
menu.findItem(R.id.move_down).setEnabled(false);
menu.findItem(R.id.move_down).setEnabled(true);
代码示例来源:origin: stackoverflow.com
@Override
public void onCreateContextMenu(ContextMenu contextMenu,
View v,
ContextMenu.ContextMenuInfo menuInfo) {
AdapterView.AdapterContextMenuInfo info =
(AdapterView.AdapterContextMenuInfo) menuInfo;
selectedWord = ((TextView) info.targetView).getText().toString();
selectedWordId = info.id;
contextMenu.setHeaderTitle(selectedWord);
contextMenu.add(0, CONTEXT_MENU_EDIT_ITEM, 0, R.string.edit);
contextMenu.add(0, CONTEXT_MENU_DELETE_ITEM, 1, R.string.delete);
}
代码示例来源:origin: stackoverflow.com
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
menu.setHeaderTitle("Select The Action");
menu.add(0, v.getId(), 0, "Call");//groupId, itemId, order, title
menu.add(0, v.getId(), 0, "SMS");
}
代码示例来源:origin: stackoverflow.com
@Override
public void onCreateContextMenu(ContextMenu menu, View v,ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
menu.setHeaderTitle("Context Menu");
menu.add(0, v.getId(), 0, "Action 1");
menu.add(0, v.getId(), 0, "Action 2");
}
@Override
public boolean onContextItemSelected(MenuItem item) {
if(item.getTitle()=="Action 1"){function1(item.getItemId());}
else if(item.getTitle()=="Action 2"){function2(item.getItemId());}
else {return false;}
return true;
}
代码示例来源:origin: stackoverflow.com
name = (TextView) itemLayoutView.findViewById(R.id.rvname);
itemLayoutView.setOnClickListener(this);
itemLayoutView.setOnCreateContextMenuListener(this);
String location = name.getText().toString();
Intent goFlip = new Intent(RecyclerAdapter.context, FlipActivity.class);
Bundle bundle = new Bundle();
menu.setHeaderTitle("Select Action");
MenuItem edit = menu.add(Menu.NONE,1,1,"Edit");
MenuItem delete = menu.add(Menu.NONE,2,2,"Delete");
edit.setOnMenuItemClickListener(onChange);
delete.setOnMenuItemClickListener(onChange);
switch (item.getItemId()){
case 1:
Toast.makeText(context,"Edit",Toast.LENGTH_LONG).show();
代码示例来源:origin: ukanth/afwall
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
AdapterView.AdapterContextMenuInfo aInfo = (AdapterView.AdapterContextMenuInfo) menuInfo;
//ProfileData profile = profileAdapter.getItem(aInfo.position);
String name = ((TextView) aInfo.targetView.findViewById(R.id.pro_name)).getText().toString();
menu.setHeaderTitle(getString(R.string.select) + " " + name);
if (G.isProfileMigrated()) {
menu.add(0, MENU_RENAME, 0, getString(R.string.rename));
// menu.add(0, MENU_CLONE, 0, getString(R.string.clone));
}
menu.add(0, MENU_DELETE, 0, getString(R.string.delete));
}
代码示例来源:origin: stackoverflow.com
super(view);
mTitleTextView = (TextView)view.findViewById(R.id.title);
view.setOnCreateContextMenuListener(mOnCreateContextMenuListener);
mTitleTextView.setText(title);
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
if (mData!= null) {
MenuItem myActionItem = menu.add("My Context Action");
myActionItem.setOnMenuItemClickListener(mOnMyActionClickListener);
代码示例来源:origin: stackoverflow.com
@Override
public void onCreate(Bundle savedInstanceState) {
listView = (ListView) findViewById(R.id.your_list_view);
registerForContextMenu(listView);
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
menu.setHeaderTitle(getString(R.string.menu_context_title));
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.your_context_menu, menu);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
switch (item.getItemId()) {
case R.id.some_item:
// do something useful
return true;
default:
return super.onContextItemSelected(item);
}
代码示例来源:origin: stackoverflow.com
public MyViewViewHolder(View itemView){
super(itemView);
itemView.setOnCreateContextMenuListener(this);
itemView.setOnClickListener(this);
nameText= ...
nameText.setText(name);
displayName=name;
menu.add(0, R.id.menuitemid, 0, "Delete").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
代码示例来源:origin: stackoverflow.com
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
//user has long pressed your TextView
menu.add(0, v.getId(), 0, "text that you want to show in the context menu - I use simply Copy");
//cast the received View to TextView so that you can get its text
TextView yourTextView = (TextView) v;
//place your TextView's text in clipboard
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
clipboard.setText(yourTextView.getText());
}
代码示例来源:origin: k9mail/k-9
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
menu.setHeaderTitle(R.string.manage_identities_context_menu_title);
getMenuInflater().inflate(R.menu.manage_identities_context, menu);
}
代码示例来源:origin: stackoverflow.com
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.comments_context, menu);
menu.setHeaderTitle("Available Actions");
MenuItem Edit = menu.findItem(R.id.editComment);
MenuItem Delete = menu.findItem(R.id.deleteComment);
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
int position = info.position;
ListView lv = (ListView) v;
int firstVisible = lv.getFirstVisiblePosition();
View rowView = lv.getChildAt(position - firstVisible);
ReviewUser = ((TextView) rowView.findViewById(R.id.labelReviewCommentUser))
.getText().toString();
ReviewComment = ((TextView) rowView.findViewById(R.id.labelReviewComment))
.getText().toString();
}
代码示例来源:origin: calvinaquino/LNReader-Android
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
MenuInflater inflater = getActivity().getMenuInflater();
inflater.inflate(R.menu.context_menu_update_history, menu);
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
UpdateInfoModel chapter = updateList.get(info.position);
if (chapter.getUpdateType() == UpdateTypeEnum.NewNovel) {
menu.findItem(R.id.menu_open_chapter).setVisible(false);
} else {
menu.findItem(R.id.menu_open_chapter).setVisible(true);
}
}
代码示例来源:origin: stackoverflow.com
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
menu.setHeaderTitle(R.string.menu_title);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.context_menu, menu);
// loop for menu items
for (int i = 0; i < menu.size(); ++i) {
MenuItem mi = menu.getItem(i);
// check the Id as you wish
if (mi.getItemId() == R.id.item2) {
mi.setChecked(true);
}
}
}
代码示例来源:origin: stackoverflow.com
menu.setHeaderTitle(name);
MenuInflater inflater = this.getActivity().getMenuInflater();
inflater.inflate(R.menu.menulistitem, menu);
MenuItem mi = menu.findItem(R.id.action_context_delete);
Intent i = new Intent();
mi.setIntent(i);
public boolean onContextItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_context_delete:
Intent i = item.getIntent();
if (i != null) {
Bundle b = i.getExtras();
代码示例来源:origin: stackoverflow.com
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo){
super.onCreateContextMenu(menu, v, menuInfo);
if (v.getId()==R.id.lvCentrais){
menu.setHeaderTitle(R.string.operacoes);
String[] menuitems = getResources().getStringArray(R.array.menu_acoes_central);
for (int i=0;i<menuitems.length;i++){
menu.add(Menu.NONE,i,i,menuitems[i]);
for (int i=0;i<menu.size();i++){
menu.getItem(i).setOnMenuItemClickListener(new OnMenuItemClickListener() {
int menuindex = item.getItemId();
代码示例来源:origin: gateship-one/odyssey
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
if (v.getId() == R.id.list_linear_listview && mNowPlayingDragStatus == DRAG_STATUS.DRAGGED_UP) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.context_menu_current_playlist, menu);
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
try {
if (getPlaybackService().getCurrentIndex() == info.position) {
menu.findItem(R.id.view_current_playlist_action_playnext).setVisible(false);
}
} catch (RemoteException e) {
e.printStackTrace();
}
CurrentPlaylistView currentPlaylistView = findViewById(R.id.now_playing_playlist);
// check if track has a valid album key
String albumKey = currentPlaylistView.getAlbumKey(info.position);
AlbumModel tmpAlbum = MusicLibraryHelper.createAlbumModelFromKey(albumKey, getApplicationContext());
menu.findItem(R.id.view_current_playlist_action_showalbum).setVisible(tmpAlbum != null);
// check if track has a valid artist id
String artistTitle = currentPlaylistView.getArtistTitle(info.position);
long artistID = MusicLibraryHelper.getArtistIDFromName(artistTitle, this);
menu.findItem(R.id.view_current_playlist_action_showartist).setVisible(artistID != -1);
// check the view type
if (currentPlaylistView.getItemViewType(info.position) == CurrentPlaylistAdapter.VIEW_TYPES.TYPE_SECTION_TRACK_ITEM) {
menu.findItem(R.id.view_current_playlist_action_remove_section).setVisible(true);
}
}
}
代码示例来源:origin: TeamNewPipe/NewPipe
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
MenuInflater inflater = getActivity().getMenuInflater();
SoftwareComponent component = (SoftwareComponent) v.getTag();
menu.setHeaderTitle(component.getName());
inflater.inflate(R.menu.software_component, menu);
super.onCreateContextMenu(menu, v, menuInfo);
mComponentForContextMenu = (SoftwareComponent) v.getTag();
}
内容来源于网络,如有侵权,请联系作者删除!