I’m trying to create an android context menu (the one that pops-up when you press the ‘menu’ button’). I’ve read all the tutorials I could find and nothing helped. I’m new to android developing.
I’ve created the menu.xml file but I don’t understand how to give functionality to ID’s. This is how my code looks:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.new_game:
newGame();
return true;
case R.id.help:
showHelp();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
The thing that I don’t get: what to do with ‘newGame();’ and ‘showHelp();’. I wish that when I click on a menu button a new activity starts. How do I do it?
First thing is you have code is for option menu not for context menu
you can call new activity like below
You can directly call a new activity without using option menu by
if you want to give option to user on press menu button then try below code