我想通过viewpager创建电子书阅读器,这本书有600页,这是创建600视图的不好方法,因为它需要大量的内存。在每个页面我用sqlite数据库填充视图< / p>
我认为我必须创建2个视图并替换后向和前向页面的视图。
我查了这个链接 http://developers-club.com/posts/132406/
我的代码
Fragment khatm1 =new RootFragment();
Fragment khatm2 = new StaticFragment();
/* PagerAdapter class */
public class SlidePagerAdapter extends FragmentPagerAdapter {
public SlidePagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
/*
* IMPORTANT: This is the point. We create a RootFragment acting as
* a container for other fragments
*/
if (currentItm > 604 || currentItm < 1){
return null;
}
else {
if (currentItm == 0)
return new RootFragment();
else
return new StaticFragment();
}
}
@Override
public int getCount() {
return NUM_ITEMS;
}
@Override
public Object instantiateItem(View container, int position) {
if (position == getCount() - 1) {
if (khatm1 == null) {
return super.instantiateItem(container, position);
} else {
return khatm1;
}
} else {
return super.instantiateItem(container, position);
}
}
@Override
public void destroyItem(View container, int position, Object object) {
if (position == getCount() - 1) {
} else {
super.destroyItem(container, position, object);
}
}
}
我如何解决我的问题?