Context (Option) Menu: Android Programming

Please login in order to report media.

  • Uploaded 9 months ago in the category How to programming

    Demonstration on how to create a context menu (options menu) on the Android phone.
    Support videos via Patreon: https://www.patreon.com/DrBFraser

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

  • contextoptionmenu:androidprogramming