Context (Option) Menu: Android Programming @DrBFraser
Context (Option) Menu: Android Programming  @DrBFraser
Uploaded February 2013 | Updated September 2026, 2 weeks ago
Demonstration on how to create a context menu (options menu) on the Android phone.

Contents:
- Understanding the context menu.
- Adding items to a context menu.
- Responding to click events for the menu: launching another activity or changing text in a TextView.
- Adding an icon to the context menu.

Sample icons I show are from the Annadroid Tehxseven icon pack: themebowl.com/annadroid-icons-by-tehkseven.html


Code:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
super.onOptionsItemSelected(item);

// Dump out the event:
String message = "Title: " + item.getTitle()
+ ", id=" + item.getItemId();
Toast.makeText(this, message, Toast.LENGTH_LONG).show();

switch(item.getItemId()) {
case R.id.menu_help:
startActivity(new Intent(this, HelpActivity.class));
break;

case R.id.menu_settings:
TextView textView = (TextView) findViewById(R.id.mainText);
textView.setText("You changed the text!");
}

return true;
}
Context (Option) Menu: Android ProgrammingApp Bar (ActionBar/Toolbar): Android ProgrammingConnecting a Photoresistor (Photo cell) to a BeagleBone Greenmain(), functions, if, loop: Java for ProgrammersLinked List in C w/ Seg Fault DebuggingJUnit 4 with IntelliJ: Exceptions, Ignore, ...Cross Debugging SegFaults with GDB: Embedded LinuxWorking with Layouts: Android ProgrammingAlertDialog via Fragment: Android ProgrammingConnect/Remove Beaglebone Capepthreads #1: IntroductionOptiTune: Remote Desktop Support
Brian Fraser |

Context (Option) Menu: Android Programming

SHARE TO X SHARE TO REDDIT SHARE TO FACEBOOK WALLPAPER