Option Menu does not appear in Android

Flip120 picture Flip120 · Sep 12, 2012 · Viewed 11.9k times · Source

I have this code to create the menu:

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

}


@Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {
    case MNU_PREV:
        animateTextViewsPrev();
        break;

    case MNU_NEXT:
        animateTextViewsNext();
        break;
    }

    return true;
}

And the XML:

<?xml version="1.0" encoding="utf-8"?>
    <menu xmlns:android="http://schemas.android.com/apk/res/android" >
        <item android:id="@+id/prev_tip" android:title="@string/prevTip"></item>
        <item android:id="@+id/next_tip" android:title="@string/nextTip"></item>
    </menu>

In a smartphone with Android 2.1 the menu is visible but in other mobile whit 4.1.1 is invisible. Somebody now how to solve it?

Answer

FIG-GHD742 picture FIG-GHD742 · Sep 12, 2012

What is you target Android, good to know, in android 4.0 them has redesign the menu layout.

I think you is missing super.onCreateOptionsMenu(menu); in the call onCreateOptionsMenu

In my code I has,

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