Search code examples
androidandroid-actionbarmenuitemactionbarsherlockmapactivity

Android: How to add menu items to a ActionBarSherlock MapActivity


I am using ActionBarSherlock with ActionBarSherlock-Plugin-Maps in my project. I would like to add menu items to the actionbar of my MapActivity as it is possible for a standard activity that inherits from SherlockActivity. The following code sample shows how to create an icon.

public class CustomSherlockActivity extends SherlockActivity {
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        menu.add("Save")
            .setIcon(R.drawable.ic_compose)
            .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
        return true;
    }

However, I can not use the same method in my MapActivity that extends SherlockMapActivity. The method SherlockMapActivity#onCreateOptionsMenu is defined final. Here is the source code of SherlockMapActivity. How then, am I supposed to add actions to the actionbar?


Solution

  • You have the wrong Menu class imported. Make sure you are importing the one from the com.actionbarsherlock.view package.