使用viewpager时,遇到了一个bug;提示fragment没有空的构造方法;
是因为当系统回收后,viewpager会调用你写的fragment的空构造方法重新实例化,所以,传参数不能放在构造方法里;
想要给系统实例化的fragment传参数,可以重写FragmentPagerAdapter中的一个方法:
@Override
public Object instantiateItem(ViewGroup container, int position) {
// TODO Auto-generated method stub
return super.instantiateItem(container, position);
}
其中
super.instantiateItem(container, position);
他的返回值就是系统自己实例化的那个fragment;