Jaison Brooks
Jaison Brooks

Reputation: 5826

ABS - Fragments - Menu inflation issue

So im getting the following problem getSupportMenuInflater() is undefined.

This project is using ActionBarSherlock and ViewPagerIndicator libraries.

I'm sure this issue is not related to my imports for ABS, however it only seems to be happening in my actual Fragment class which extends SherlockFragment However i have no problem with menu items in my Main class which extends SherlockFragmentActivity

Now i've tried simply changing my fragment class to extend SherlockFragmentActivity. However in doing so i am then force to remove all @Override's and then i end with the following error

The method onActivityCreated(Bundle) is undefined for the type SherlockFragmentActivity.

Code

public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater Inflater = getSupportMenuInflater();
    Inflater.inflate(R.menu.menu_main, menu);
    return true;    
    }

Resolved Updated code to the following.

 public void onCreateOptionsMenu(Menu menu) {
    getSherlockActivity().getSupportMenuInflater().inflate(R.menu.menu_main, menu);
    return;

Upvotes: 0

Views: 340

Answers (1)

Ronak Mehta
Ronak Mehta

Reputation: 5979

You need to use:

getSherlockActivity().getSupportMenuInflater().inflate(R.menu.activity_main, menu);

Since getSupportMenuInflater() is a method in SherlockActivity not SherlockFragment.

Reference Link

Upvotes: 1

Related Questions