*
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
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: 4167
    
  21

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: 4167
    
  21

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.
 
Consider Paul's rocket mass heater.
 
subject: Problem with onCreateOptionsMenu
 
Similar Threads
launch skype after click button in the app
Create a simple Layout
Maps are not show in Emulator
java code for speech to text
Why not correct run my program?