这是我的片段页面适配器。
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
public class MyFragmentPagerAdapter extends FragmentPagerAdapter {
private String[] pageTitle = {
"Page1", "Page2", "Page3"
};
public MyFragmentPagerAdapter(FragmentManager fragmentManager) {
super(fragmentManager);
}
@Override
public Fragment getItem(int position) {
switch (position) {
case 0: return new PageFragment();
case 1: return new PageFragment2();
case 2: return new PageFragment3();
}
Fragment fragment = new PageFragment();
Bundle arguments = new Bundle();
arguments.putString("pageIndex", Integer.toString(position + 1));
fragment.setArguments(arguments);
return fragment;
}
@Override
public int getCount() {
return pageTitle.length;
}
@Override
public CharSequence getPageTitle(int position) {
return pageTitle[position];
}
}
为什么我在这一行出现错误:案例0:返回新的PageFragment();和 Fragment 片段 = new PageFragment(); 错误是“类型不匹配:无法从 PageFragment 转换为 Fragment”如何解决?是否可以使其 (Viewpager) 与 Android 2.2 或 2.3 兼容?