erdemgc
erdemgc

Reputation: 1721

getSupportMenuInflater or getMenuInflate method does not get recognized

I have ListFragment and getSupportMenuInflater() method is not recognized.

public boolean onCreateOptionsMenu(Menu menu) {
        // TODO Auto-generated method stub
    getSupportMenuInflater().inflate(R.menu.welcome, menu);
    return true;
    }

what do i need to define?

Upvotes: 4

Views: 4950

Answers (3)

jordivilagut
jordivilagut

Reputation: 343

If you are on a Fragment, you should get the Activity and apply getMenuInflater() to it.

@Override
    public void onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(menu);
        getActivity().getMenuInflater().inflate(R.menu.welcome, menu);
    }

Upvotes: 2

Shani Goriwal
Shani Goriwal

Reputation: 2104

You should use:

public boolean onCreateOptionsMenu(Menu menu) {
   getActivity().getSupportFragmentManager().inflate(R.menu.welcome, menu);
   return true;
}

Upvotes: 0

No_Rulz
No_Rulz

Reputation: 2719

You need to use

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

Looks like getSherlockActivity is just a shortcut to:

(SherlockActivity) getActivity()

Upvotes: 0

Related Questions