@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); getMenuInflater().inflate(R.menu.context_menu, menu); }
@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); menu.setHeaderTitle("Options"); menu.add(0, 1, 0, "Edit"); menu.add(0, 2, 0, "Delete"); }In this example, we create a context menu programmatically using the add method. We set the menu title using the setHeaderTitle method, and add two options: "Edit" and "Delete". The package library used in this example is the android.view package.