开发者

Android menu will not appear when the menu button is pressed in AVD

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 co开发者_JAVA技巧okie
        finish();
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜