Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 847
nasaa Avatar asked Dec 04 '25 16:12

nasaa


1 Answers

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()

like image 153
Ovidiu Latcu Avatar answered Dec 07 '25 05:12

Ovidiu Latcu