This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Android and the fly likes Problem with onCreateOptionsMenu Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Mobile » Android
Bookmark "Problem with onCreateOptionsMenu" Watch "Problem with onCreateOptionsMenu" New topic
Author

Problem with onCreateOptionsMenu

Grigoriy Gusarov
Greenhorn

Joined: Jan 10, 2013
Posts: 1
Hello all.

I need to ovveride method onCreateOptionmenu, but i can`t find it in "override/implement methods".

My code:
package com.gusarov.menu;

import android.os.Bundle;
import android.app.Activity;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.Menu;
import android.view.View;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;

}

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





[Thumbnail for Безымянный.png]

Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 3969
    
  17

I don't know what the IDE is doing, but you can see the method here:
http://developer.android.com/reference/android/app/Activity.html#onCreateOptionsMenu(android.view.Menu)

And it indicates it existed since API level 1, so no chance of having too old a version...


Steve
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 3969
    
  17

Just played with Eclipse: looks like the IDE removes the method from the list of methods to insert/override if you have already inserted/overriden it. So since your Activity already has the boolean onCreateOptionsMenu(Menu) method, that method is removed from the list.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with onCreateOptionsMenu
 
Similar Threads
Create a simple Layout
Why not correct run my program?
launch skype after click button in the app
java code for speech to text
Maps are not show in Emulator