In Activity class, there is method called registerForContextMenu(View view).
The android document explains that this method is used to registers a context menu to be shown for the given view (multiple views can show the context menu).
registerForContextMenu(View view), it is not clear to me to just read the document online.A context menu is a pop-up menu that provides shortcuts for actions the software developer anticipates the user might want to take. In a Windows environment, the context menu is accessed with a right mouse click.
Context menus enable you to provide choices to users for interaction with graphics objects. Program a context menu when you want user to be able to: Choose among specific options by right-clicking a graphics object.
A context menu (also called contextual, shortcut, and pop up or pop-up menu) is a menu in a graphical user interface (GUI) that appears upon user interaction, such as a right-click mouse operation.
A context menu is a floating menu that appears when the user performs a long-click on an element. It provides actions that affect the selected content or context frame.
It's basically a pop-up menu that is displayed when you long-click certain UI elements (usually an item in a ListView).
You should take a look at the Menus section of the Developer Guide.
This is from Android Developers: Menu -Android Developers
A context menu is a floating menu that appears when the user performs a long-click on an element. It provides actions that affect the selected content or context frame.
Imagine that you want a conext menu in a listview
//Constants for context menu options
public static final int MENU_MARK = 1;
public static final int MENU_REMOVE = 2;
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
...
...
// Specify that your listview has a context menu attached
registerForContextMenu(getListView());
}
// here you create the context menu
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
menu.add(Menu.NONE, MENU_MARK, Menu.NONE, "MARK");
menu.add(Menu.NONE, MENU_REMOVE, Menu.NONE, "Remove");
}
// This is executed when the user selects an option
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
switch (item.getItemId()) {
case MENU_MARK:
mark_item(info.id);
return true;
case MENU_REMOVE:
delete_item(info.id);
return true;
default:
return super.onContextItemSelected(item);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With