SherlockFragment onCreateOptionsMenu不调用 [英] SherlockFragment onCreateOptionsMenu is not calling
问题描述
在我的应用我有延伸类的 SherlockFragmentActivity 。在这一活动,我加载四班延伸的 SherlockFragment 其中pretends为的标签的用 ActionbarSherlock 的<帮助/ strong>和 PagerSlidingTabStrip 的
In my app I'm having a class which extends SherlockFragmentActivity. Within that Activity, I'm loading four classes which extends SherlockFragment which pretends as Tabs with the help of ActionbarSherlock and PagerSlidingTabStrip.
它扩展的类的 SherlockFragment 的 setHasOptionsMenu(真); 的在 的onCreate()的方式。即使是具有运行应用程序时,它不会叫 onCreateOptionsMenu()的方式。
The classes which extends SherlockFragment has setHasOptionsMenu(true); inside onCreate() method. Even having that, when run the application, it won't call onCreateOptionsMenu() method.
我看了这些类似的问题(<一个href=\"http://stackoverflow.com/questions/11855581/how-can-i-use-oncreateoptionsmenu-in-a-fragment-within-a-tab-activity-sherlock?rq=1\">Q1, Q2 )的SO,并没有得到任何帮助。
I have read these similar questions (Q1, Q2) in SO and didn't get any help.
有什么可以为什么原因呢?
What can be the reason for that?
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
menu.clear();
inflater.inflate(R.menu.record, menu);
super.onCreateOptionsMenu(menu, inflater);
Log.i(TAG, "* onCreateOptionsMenu");
}
更新:
我想原因是,我使用的是另一种SherlockFragment里面SherlockFragment。意味着<一个href=\"https://github.com/astuetz/PagerSlidingTabStrip/blob/master/sample/src/com/astuetz/viewpager/extensions/sample/MainActivity.java\"相对=nofollow> PageSlidingTabStripFragment.java 内部有如下方法 MyPagerAdapter 类。
I think the reason is, I'm using SherlockFragment inside another SherlockFragment. Means in PageSlidingTabStripFragment.java has following method inside MyPagerAdapter class.
@Override
public SherlockFragment getItem(int position) {
return SuperAwesomeCardFragment.newInstance(position);
}
我在做什么时,我打电话从有一些其他SherlockFragments像下面。
What I'm doing is, I'm calling some other SherlockFragments from there like below.
@Override
public SherlockFragment getItem(int position) {
Log.i(TAG, "* getItem");
switch (position) {
case 0:
return new InnerSherlockFragmentOne();
case 1:
return new InnerSherlockFragmentTwo();
case 2:
return new InnerSherlockFragmentThree();
case 3:
return new InnerSherlockFragmentFour();
default:
return null;
}
}
什么是不叫的 onCreateOptionsMenu(菜单菜单,MenuInflater吹气)这些InnerSherLockFragments内。
What is not calling is onCreateOptionsMenu(Menu menu, MenuInflater inflater) inside those InnerSherLockFragments.
推荐答案
进口应该是:
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
而不是这些Android操作系统的!
and not these of android OS!
也可以尝试调用超级
方法如下:
Also try calling super
method like:
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
menu.clear();
inflater.inflate(R.menu.record, menu);
Log.i(TAG, "* onCreateOptionsMenu");
}
这篇关于SherlockFragment onCreateOptionsMenu不调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!