JSBach
JSBach

Reputation: 4747

My menu in my activity is not appearing because my onCreateOptionsMenu is not getting called

I am learning android with the book Android in Action. One of the examples is a simple app with this menu bar in the lower part of the screen. I have this code to draw the menu:

        @Override
      public boolean onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(menu);
        menu.add(0, ReviewCriteria.MENU_GET_REVIEWS, 0, R.string.menu_get_reviews).setIcon(android.R.drawable.ic_menu_more);
        return true;
    }

But it doesn't get called so the menu is not appearing. I tried to set a breakpoint on it but it doesn't stop on it. Do I have to set any other property to enable the menu in this activity?

Thanks, Oscar

Edit: the LogCat is full of log entries regarding the emulator start-up. These are the ones related to mine app deployment/load

04-07 22:26:08.403: INFO/System.out(480): debugger has settled (1503)
04-07 22:26:16.404: WARN/InputManagerService(73): Got RemoteException sending setActive(false) notification to pid 447 uid 10034
04-07 22:26:16.933: INFO/ActivityManager(73): Displayed com.examples.RestaurantFinder/.ReviewCriteria: +16s325ms (total +16s431ms)
04-07 22:26:37.705: DEBUG/SntpClient(73): request time failed: java.net.SocketException: Address family not supported by protocol
04-07 22:30:24.473: ERROR/ThrottleService(73): Error reading data file
04-07 22:31:37.745: DEBUG/SntpClient(73): request time failed: java.net.SocketException: Address family not supported by protocol

It doesn't seem to give any information about the menu :(

Upvotes: 1

Views: 8517

Answers (2)

Sunil Chaudhary
Sunil Chaudhary

Reputation: 1247

inherit your activity from ActionBarActivity and add in your mainifest android:theme="@style/Theme.AppCompat" under same activity name

Upvotes: 0

Squonk
Squonk

Reputation: 48871

Sorry, stupid question....you are pressing the MENU button to display the options menu? What is in the options menu that is shown?

EDIT: There are two types of 'menu' in Android.

The Options menu is triggered/displayed using the MENU button on the device.

The other type of menu is a Context menu - in this case a particular 'view' has to be registered for a context menu and it's triggered by a long-press on that view. This means different parts (views) within your UI can have their own context menus allowing different actions to be performed relating to the view.

Upvotes: 7

Related Questions