已解决:ViewPager的notifyDataSetChanged不刷新问题

1.ViewPager的适配器必须继承FragmentStatePagerAdapter才能刷新。
2.要在destroyItem加摧毁View的代码
3.在getItemPosition方法中返回POSITION_NONE。
这样,我们在调用mAdapter.notifyDataSetChanged()时才能刷新
具体实现如下:
classMyAdapterextendsFragmentStatePagerAdapter{
privateArrayListreturnFragment;
publicMyAdapter(FragmentManager fm,ArrayList returnFragment) {
super(fm);
this.returnFragment= returnFragment;
}
@Override
publicFragment getItem(intposition) {
returnreturnFragment.get(position);
}
@Override
public void destroyItem(ViewGroup container,intposition, Object object) {
super.destroyItem(container, position, object);
container.removeView(returnFragment.get(position).getView());
}
@Override
public int getCount() {
Log.i("tian","getCount: "+returnFragment.size());
returnreturnFragment.size();
}
@Override
public int getItemPosition(Object object) {
returnPOSITION_NONE;
}
}

你可能感兴趣的:(Android)