如何在Android上重置ViewPager

如何在Android上重置ViewPager

本文介绍了如何在Android上重置ViewPager内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请告诉我如何在android上重置ViewPager的内容.我尝试调用adapter.notifyDataSetChanged(),但是在滚动视图时适配器不调用getItem(position).它总是返回旧的子视图.

Please tell me how to reset the content of ViewPager on android.I tried to call adapter.notifyDataSetChanged() but the adapter doesn't call getItem(position) when I scroll the view. It always returns old child views.

更新:这是我的片段视图.当我重置viewPager数据时,它使用了加载的Fragment视图.它只是从onCreateView而不是Constructor开始.

Update: This is my Fragment View. When I reset viewPager data, It used loaded Fragment views. It's just start at the onCreateView instead of Constructor.

public class ResultView extends Fragment {
//Declare properties

     //Constructor
public ResultView(Province province, Calendar calendar) {
    Log.d("xskt", "ResultView constructor");
    this.province = province;
    this.calendar = (Calendar) calendar.clone();
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Log.d("xskt", "ResultView onCreateView");
    View view = inflater.inflate(R.layout.resultview, null);

    //do some thing

    return view;
}

谢谢.

推荐答案

我已更改为使用FragmentStatePagerAdapter而不是FragmentPagerAdapter,此问题已解决.希望这会有所帮助.

I have changed to use FragmentStatePagerAdapter instead of FragmentPagerAdapter, the problem is resolved. Hope this helps.

这篇关于如何在Android上重置ViewPager内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 00:46