java android.support.v4.app.FragmentPagerAdapter 不能应用于 android.app.FragmentManager
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28916294/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
android.support.v4.app.FragmentPagerAdapter cannot be applied to android.app.FragmentManager
提问by Nikhil
I want to implement just 2 fixed tabs in my application. I followed this tutorial.
我只想在我的应用程序中实现 2 个固定选项卡。我跟着这个教程。
In my TabPagerAdapterclass I'm getting this error :
在我的TabPagerAdapter课堂上,我收到此错误:
FragmentPageAdapterin android.support.v4.app.FragmentPagerAdaptercannot be applied to android.app.FragmentManager
FragmentPageAdapterinandroid.support.v4.app.FragmentPagerAdapter不能应用于android.app.FragmentManager
TabPageAdapter class:
TabPageAdapter 类:
package com.nikhil.tabs;
import android.app.Fragment;
import android.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
public class TabsPagerAdapter extends FragmentPagerAdapter {
public TabsPagerAdapter(FragmentManager fm) {
super(fm); //getting error here
}
@Override
public Fragment getItem(int index) { //getting error here
switch (index) {
case 0:
// Top Rated fragment activity
return new TopRatedFragment();
case 1:
// Games fragment activity
return new GamesFragment();
}
return null;
}
@Override
public int getCount() {
// get item count - equal to number of tabs
return 2;
}
}
Why is that error caused and how to solve it?
为什么会导致该错误以及如何解决?
回答by Apurva
Error occurs because your FragmentPagerAdapteruses support librariesand Fragmentand FragmentManagerdon't!
发生错误,因为您FragmentPagerAdapter使用支持库,并Fragment与FragmentManager别!
Change
改变
import android.app.Fragment;
import android.app.FragmentManager;
To
到
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;

