Unable to override onCreateOptionsMenu in ListFragment

Waza_Be picture Waza_Be · Oct 21, 2011 · Viewed 32.8k times · Source

I created an app that supports both phone and tablet version so i use the android-support-v4.jar library.

My activity extends the ListFragment and I tried to override the onCreateOptionsMenu(Menu menu, MenuInflater inflater), as in the following link: http://developer.android.com/resources/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentMenuSupport.html

I previously called setHasOptionsMenu.

Unfortunately, it seems that I cannot override onCreateOptionsMenu().

This is the error message:

The method onCreateOptionsMenu(Menu menu, MenuInflater inflater) of type MyFragment must override or implements a supertype method.

And I did that with:

Public class MyFragment extends ListFragment

Answer

Maria Neumayer picture Maria Neumayer · Oct 21, 2011

Make sure the imports are from the compatibility library and not from the SDK itself.