我的应用程序正在使用 android 支持库 rev 12,但是当我更新到修订版 13 时,我的 FragmentStatePagerAdapter 开始让我发疯:
我的活动:
import android.app.Fragment;
import android.app.FragmentManager;
import android.support.v13.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
...
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mAdapter = new MyAdapter(getFragmentManager());
mPager = (ViewPager)findViewById(R.id.main_frame_pager);
mPager.setAdapter(mAdapter);
}
public static class MyAdapter extends FragmentStatePagerAdapter {
public MyAdapter(FragmentManager fm) {
super(fm);
}
@Override
public int getCount() {
return 5;
}
@Override
public Fragment getItem(int position) {
Log.i(TAG, "getItem() -> New fragment at position " + position);
switch (position) {
case 0:
IdentityFragment idFrag = new IdentityFragment();
return idFrag;
case 1:
SkillFragment skFrag = new SkillFragment();
return skFrag;
case 2:
ExperiencesFragment expFrag2 = new ExperiencesFragment();
return expFrag2;
case 3:
EducationFragment eduFrag = new EducationFragment();
return eduFrag;
case 4:
MiscFragment mFrag = new MiscFragment();
return mFrag;
}
return null;
}
}
我的所有片段都被实例化(LogCat 显示“getItem() -> 位置 [0 -> 4] 处的新片段”),而预期只有 0 和 1(offscreenPageLimit = 1)