无法重写ListFragment中的onCreateOptionsMenu [英] Unable to override onCreateOptionsMenu in ListFragment
问题描述
我创建了一款支持手机和平板电脑版本的应用程序,因此我使用了android-support-v4.jar库。
I created an app that supports both phone and tablet version so i use the android-support-v4.jar library.
我的活动扩展了ListFragment,我尝试覆盖onCreateOptionsMenu(Menu Menu,MenuInflater inflater),如下面的链接所示: http://developer.android.com/resources/samples/Support4Demos /src/com/example/android/supportv4/app/FragmentMenuSupport.html
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
我以前叫setHasOptionsMenu。
I previously called setHasOptionsMenu.
不幸的是,我似乎无法重写onCreateOptionsMenu()。
Unfortunately, it seems that I cannot override onCreateOptionsMenu().
这是错误信息:
This is the error message:
类型MyFragment的onCreateOptionsMenu(Menu menu,MenuInflater inflater)方法必须覆盖或实现超类型方法。
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
推荐答案
确认的进口从兼容性库,而不是从SDK本身。
Make sure the imports are from the compatibility library and not from the SDK itself.
这篇关于无法重写ListFragment中的onCreateOptionsMenu的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!