Creating Options menu in Android
Asked Answered
C

4

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

Coiffure answered 23/1, 2012 at 10:17 Comment(2)
This is for which Android Version?Santalaceous
See here: #13267530Accolade
S
2

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

Septarium answered 23/1, 2012 at 10:22 Comment(7)
I tried without super.onCreateOptionsMenu(menu). but still am not getting the menu. Is it a problem with the full screen view?Coiffure
no. it shouldn't be a problem with full screen. Clean your project and then runSeptarium
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?Coiffure
are you overriding this in your activity? just thought to confirm :)Septarium
yes. Am overriding it :) and I am using ActivityGroup in my program. Does this create any issue with menu?Coiffure
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 groupSeptarium
hmmm try adding to ActivityGroup and see, because i just tested it doing on one of my own ActivityGroup and it workedSeptarium
S
0

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

Santalaceous answered 23/1, 2012 at 10:20 Comment(1)
Android version is 2.2. I am pressing the options menu at the bottom. But still the code is not working.Coiffure
D
0

Don't call

super.onCreateOptionsMenu(menu);

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

Discography answered 23/1, 2012 at 10:22 Comment(0)
K
0

Use this code:

public boolean onCreateOptionsMenu(Menu menu) {
      MenuInflater inflater = getMenuInflater();
      inflater.inflate(R.menu.options_menu, menu);
      return true;
    }
Kandace answered 23/1, 2012 at 10:25 Comment(1)
I tried your code without "super.onCreateOptionsMenu(menu); " working perfectly for me..Kandace

© 2022 - 2024 — McMap. All rights reserved.