Context (Option) Menu: Android Programming

Published: 15 February 2013
on channel: Brian Fraser
31,901
76

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: http://www.themebowl.com/annadroid-ic...


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;
}


On this page of the site you can watch the video online Context (Option) Menu: Android Programming with a duration of hours minute second in good quality, which was uploaded by the user Brian Fraser 15 February 2013, share the link with friends and acquaintances, this video has already been watched 31,901 times on youtube and it was liked by 76 viewers. Enjoy your viewing!