Question

I have defined a menu as laid out by http://developer.android.com/guide/topics/ui/menus.html

Here is my menu.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/menu_home"
          android:icon="@drawable/ic_menu_home"
          android:title="Main Menu" />
    <item android:id="@+id/menu_signout"
          android:icon="@drawable/ic_menu_signout"
          android:title="Sign Out" />
</menu>

and my code, placed in my activity

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle item selection
    switch (item.getItemId()) {
    case R.id.menu_home:
        startActivity(new Intent(ManageUsersActivity.this, MainMenuActivity.class));
        finish();
        return true;
    case R.id.menu_signout:
            //TODO: issue signout to clear the cookie
        finish();
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

Unfortunately, when I click the menu button, nothing happens.

Was it helpful?

Solution

Try chaining to the superclass in onCreateOptionsMenu(). Here is a sample project demonstrating the use of MenuInflater for options and context menus.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top