@Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.options_menu, menu); return true; }
@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.context_menu, menu); }In this example, the onCreateContextMenu method is called when the user performs a long press gesture on a view in the activity. The MenuInflater object is used to inflate the context_menu XML file, and the resulting menu is added to the view. The android.view.MenuInflater class is included in the android.view package library.