How do I implement an option menu in my android application? I tried code from Android Developer but I get errors. Such as these: Element menu must be declared.
You need to create a menu.xml
in directory res->menu like menu
Then you need to create your menu from activity with below code
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.help) {
//do something
return true;
}
if (id == R.id.new_game) {
//do something
return true;
}
return super.onOptionsItemSelected(item);
}