2

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?

FIG-GHD742
  • 2,486
  • 1
  • 19
  • 27
Flip120
  • 99
  • 1
  • 2
  • 10

4 Answers4

5

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;
}
FIG-GHD742
  • 2,486
  • 1
  • 19
  • 27
  • The min minSdkVersion is 7 and the targetSdkVersion is 15, is for Android 2.1 , i have the call to super but I forgot paste it. – Flip120 Sep 12 '12 at 20:49
  • Yes my code is this: `code`public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.menu, menu); return true; }`/code` – Flip120 Sep 12 '12 at 21:08
  • What is happen if you edit the targetSdkVersion to 7 and then run the app on you phone that has android 4.1.1 – FIG-GHD742 Sep 12 '12 at 21:11
  • 1
    Can you has a event listener that prevent `onCreateOptionsMenu`event? Do you know if the methods `onCreateOptionsMenu` is call for you in android 4.1.1? Also try to create a new XML files, can be some hidden error in this? – FIG-GHD742 Sep 12 '12 at 21:18
  • Yes, was that, i solve it, i have a gesture listener to implement swype gesture and a touch listener, and when i comment the code the menu appears, It was the touch listener, A lot of Thanks FIG-GHD742 – Flip120 Sep 12 '12 at 21:24
2

I was dealing with the same problem.. read some queries and documentation.. Hope this might help you.

Here's my XML file for a menu..

<item
    android:id="@+id/action_send_feedback"
    android:orderInCategory="100"
    android:showAsAction="always"
    android:title="@string/action_send_feedback"/>

<item 
    android:id="@+id/action_share_app"
    android:orderInCategory="100"
    android:showAsAction="ifRoom"
    android:title="@string/action_share_app"
    android:icon="@drawable/ic_action_share" />

<item
    android:id="@+id/action_rate_app"
    android:orderInCategory="100"
    android:showAsAction="never"
    android:title="@string/action_rate_app"/>

JAVA Code goes here..

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

For android phones which have option button (at the bottom of the phone) the menu item which are showAsAction="never" comes when the button is pressed.. or else they will be shown normally on the action bar options menu..

Ref: http://developer.android.com/guide/topics/ui/menus.html#options-menu

RaiVikrant
  • 529
  • 6
  • 15
  • THX for "For android phones which have option button (at the bottom of the phone) the menu item which are showAsAction="never" comes when the button is pressed.. or else they will be shown normally on the action bar options menu.." – Khanh Nguyen Sep 13 '14 at 01:49
0

You can simply change the "targetSdkVersion" to 10 in manifest file

vimal1083
  • 8,499
  • 6
  • 34
  • 50
-4

It needs the ID in the java! :)

apw2012
  • 233
  • 3
  • 5
  • 12