@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_news_content_slider);
if(savedInstanceState != null) {
currentFragment = savedInstanceState.getInt("currentFragment");
}
((TextView) findViewById(R.id.item_content)).setText(getIntent().getStringExtra("content"));
viewPager = new ViewPager(this);
viewPager.setId(R.id.pager);
setContentView(viewPager);
final ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionBar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);
tabsAdapter = new TabsAdapter(this, viewPager);
tabsAdapter.addTab(actionBar.newTab().setText("Simple"), NewsContent.class, null);
tabsAdapter.addTab(actionBar.newTab().setText("Tab"), NewsContent.class, null);
tabsAdapter.addTab(actionBar.newTab().setText("Create"), NewsContent.class, null);
}
public static class TabsAdapter extends FragmentStatePagerAdapter implements ActionBar.TabListener, ViewPager.OnPageChangeListener{
private final Context context;
private final ActionBar actionBar;
private final ViewPager viewPager;
private final ArrayList<TabInfo> mTabs = new ArrayList<TabInfo>();
static final class TabInfo {
private final Class<?> clss;
private final Bundle args;
TabInfo(Class<?> _class, Bundle _args) {
clss = _class;
args = _args;
}
}
public TabsAdapter(Activity activity, ViewPager pager) {
super(activity.getFragmentManager());
context = activity;
actionBar = activity.getActionBar();
viewPager = pager;
viewPager.setAdapter(this);
viewPager.setOnPageChangeListener(this);
}
我在第super(activity.getFragmentManager());
行上收到错误,因为我正在使用FragmentStatePagerAdapter的支持库。
错误是: FragmentSTatePagerAdapter中的FragmentStatePagerAdapter(android.support.v4.app.FragmentManager)无法应用于(android.app.FragmentManager)
如果我将行public TabsAdapter(Activity activity, ViewPager pager)
更改为public TabsAdapter(FragmentActivity activity, ViewPager pager)
,则错误会消失,但由于类似的原因,我会在行tabsAdapter = new TabsAdapter(this, viewPager);
上收到错误。
答案 0 :(得分:0)
如果您希望ViewPager
使用Fragment
提供的框架(即android.app.Fragment
),则可以使用包含{{{{}}版本的support-v13 library 3}}支持不支持的碎片。