0

我正在使用ActionBarSherlock库的项目。现在我想用viewpager创建选项卡。ActionBarTabs在片段类而不是活动

所以我用this教程作为参考。我想创建tabview的类是Fragment,而不是Activity

有人请帮助我将Activity类中使用的这些方法转换为Fragment的方法。

第一:

ActionBar actionBar = getSupportActionBar(); 

Error:The method getSupportActionBar() is undefined for the type Fragment

二:

viewPager.setAdapter(new ViewPagerAdapter(getSupportFragmentManager())); 

Error:The method getSupportFragmentManager() is undefined for the type Fragment

+0

好像你没有使用支持库,所以只需从api中删除所有'support',我想你的'minSDKVersion'> = 11 – Xcihnegn 2015-03-25 09:13:30

回答

1

试试这个..

ActionBar actionBar = getActivity().getSupportActionBar(); 

而且

viewPager.setAdapter(new ViewPagerAdapter(getActivity().getSupportFragmentManager()));