3

I am trying to create options menu in my Android program. I am using the following code to inflate options menu :

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

And my xml code is :

?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android="http://schemas.android.com/apk/res/android">
<item
    android:id="@+id/Option1"
    android:title="Option1"/>
<item
    android:id="@+id/Option2"
    android:title="Option2"/>
<item
    android:id="@+id/Option3"
    android:title="Option3"/>
</menu>

But with this code i am not able to show the options menu in my screen.

Also, i am using the code

android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 

to make the activity as full screen view. Does this code creates problem in inflating the menu?

Thanks in advance,

Timson

Timson
  • 1,337
  • 3
  • 19
  • 32

4 Answers4

2

remove the line super.onCreateOptionsMenu(menu); from your onCreateOptionMenu. You are actually already providing the menu before inflating it.

waqaslam
  • 67,549
  • 16
  • 165
  • 178
  • I tried without super.onCreateOptionsMenu(menu). but still am not getting the menu. Is it a problem with the full screen view? – Timson Jan 23 '12 at 10:26
  • no. it shouldn't be a problem with full screen. Clean your project and then run – waqaslam Jan 23 '12 at 10:29
  • I given a Log inside the onCreateOptionsMenu method. But log is not coming in the console. So can i assume that @Override is not working? – Timson Jan 23 '12 at 10:37
  • are you overriding this in your activity? just thought to confirm :) – waqaslam Jan 23 '12 at 10:47
  • yes. Am overriding it :) and I am using ActivityGroup in my program. Does this create any issue with menu? – Timson Jan 23 '12 at 10:49
  • it should work in ActivityGroup too. If you are using Activites to add inside your activitygroup then add this code to your activities rather than to group – waqaslam Jan 23 '12 at 10:54
  • 1
    hmmm try adding to ActivityGroup and see, because i just tested it doing on one of my own ActivityGroup and it worked – waqaslam Jan 23 '12 at 11:00
0

Options menu shows up by pressing the Options Menu button at the bottom of the phone

Rajdeep Dua
  • 11,190
  • 2
  • 32
  • 22
  • Android version is 2.2. I am pressing the options menu at the bottom. But still the code is not working. – Timson Jan 23 '12 at 10:21
0

Don't call

super.onCreateOptionsMenu(menu);

as that will return a value before your code is executed.

Kingamajick
  • 2,281
  • 1
  • 16
  • 19
0

Use this code:

public boolean onCreateOptionsMenu(Menu menu) {
      MenuInflater inflater = getMenuInflater();
      inflater.inflate(R.menu.options_menu, menu);
      return true;
    }
Nibha Jain
  • 7,742
  • 11
  • 47
  • 71