0 Replies - 390 Views - Last Post: 23 March 2011 - 11:40 AM

#1 avolel  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 42
  • Joined: 24-August 05

Android Options Menu

Posted 23 March 2011 - 11:40 AM

Hello,

I'm new to Android development and I have a question about creating an android option menu.

In my XML resource file I have

<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/settings"
          android:icon="@drawable/settings"
          android:title="@string/settings" />
    <item android:id="@+id/help"
          android:icon="@drawable/ic_help"
          android:title="@string/help" />
</menu>



I override the onCreateOptionsMenu method, inflate my menu resource and set the intent on the menu items.

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu_options, menu);
    menu.findItem(R.id.settings).setIntent(new Intent(this,Someclass.class));
    menu.findItem(R.id.help).setIntent(new Intent(this,Someclass2.class));
    return true;
}



When I ran the above code it breaks at menu.findItem. I get a NullException error. Does anyone know why menu is NULL? I thought that inflating the menu resource would set the menu object.

Another Problem:

I removed the menu.findItem from the onCreateOptionsMenu method but now in the emulator when I click the menu button I do not see any options menus showing up. Does anyone know why is this, this what the onCreateOptionsMenu look like now:

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



Thanks For Your Help

Is This A Good Question/Topic? 0
  • +

Page 1 of 1