Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mahdimortazavi/c35ea9153c87f4a4643987bde6b4717e to your computer and use it in GitHub Desktop.
Save mahdimortazavi/c35ea9153c87f4a4643987bde6b4717e to your computer and use it in GitHub Desktop.
Sample onOptionsItemSelected and onCreateOptionsMenu
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.bookmark_menu:
Toast.makeText(this, "You have selected Bookmark Menu", Toast.LENGTH_SHORT).show();
return true;
case R.id.save_menu:
Toast.makeText(this, "You have selected Save Menu", Toast.LENGTH_SHORT).show();
return true;
case R.id.search_menu:
Toast.makeText(this, "You have selected Search Menu", Toast.LENGTH_SHORT).show();
return true;
case R.id.share_menu:
Toast.makeText(this, "You have selected Share Menu", Toast.LENGTH_SHORT).show();
return true;
case R.id.delete_menu:
Toast.makeText(this, "You have selected Delete Menu", Toast.LENGTH_SHORT).show();
return true;
case R.id.print_menu:
Toast.makeText(this, "You have selected Print menu", Toast.LENGTH_SHORT).show();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment