nasaa
nasaa

Reputation: 2731

MenuInflater in SherlockActivity

I am trying to get the menu inflater inflate the menu xml in my SherlockActivity class.

My onCreateOptionsMenu method is like this -

@Override
public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) {
    MenuInflater inflater = this.getSupportMenuInflater();
    inflater.inflate(R.menu.messagespagemenu, menu);
    return true;
}

and my messagespagemenu.xml looks like this -

<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
    android:id="@+id/text"
    android:title="@string/deleteall">
</item>

And my activity class extends SherlockActivity.

Could anyone please point me to the mistake I am doing.

EDIT:

The menu is not showing. When I try this same code in another class is extending SherlockListActivity then it works. So I am wondering if I am missing anything in this class

Upvotes: 3

Views: 2780

Answers (2)

Siddharth Lele
Siddharth Lele

Reputation: 27748

Try this and see if this works:

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    MenuInflater inflate = getSupportMenuInflater();
    inflate.inflate(R.menu.messagespagemenu, menu);

    return super.onCreateOptionsMenu(menu);
}

Also, make sure this part looks exactly like in this sample above:

public boolean onCreateOptionsMenu(Menu menu)

You currently have this:

public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu)

I am not sure if that makes any difference or not, but see it works. The corresponding import should be import com.actionbarsherlock.view.Menu;

Upvotes: 0

Ovidiu Latcu
Ovidiu Latcu

Reputation: 72311

Probably you are running this on a pre-Honeycom device, and this MenuItem will be shown just if you click the hardware menu key. You should set android:showAsAction:alwaysor android:showAsAction:ifRoom on your <item>.

EDIT: you should also make the call to super.onCreateOptionsMenu()

Upvotes: 1

Related Questions