java.lang.IllegalStateException: 应用程序的 PagerAdapter 在没有调用 PagerAdapter#notifyDataSetChanged 的​​情况下更改了适配器的内容

java.lang.IllegalStateException: The application's PagerAdapter changed the adapter's contents without calling PagerAdapter#notifyDataSetChanged

我正在构建一个简单的图库应用程序。 图片与服务器同步。 现在我有一个简单的 gridView 显示图像和 onClick 图像在 viewPager 中打开。就像 android 默认图库一样。

问题是-

java.lang.IllegalStateException: The application's PagerAdapter changed the adapter's contents without calling PagerAdapter#notifyDataSetChanged!

我需要一种方法从后台通知 viewPager 的适配器。 为了在后台加载数据,我使用 Koush/Ion

CLass ImageGrid (summary)

public class ImageGrid extends Fragment implements HttpConnectCallback, FutureCallback<JsonArray> {
...
..
.
gridView.setOnItemClickListener(CustomListener);
//onClick-> the following code executes

PagerFragment pagerFragment = new PagerFragment().newInstance(position);
...
..
.

当 PagerFragment 处于活动状态时,数据加载仍在后台继续

Class PagerFragment (summary)

public class PagerFragment extends Fragment {
...
..
.
viewPager = (ViewPager) view.findViewById(R.id.splash_pager);

viewPager.setAdapter(new PagerAdapter);// a PagerAdapter 

现在 图像来源 适配器在 类 相同. 即我有一个 static ArrayList<String>,其中包含磁盘上图像的路径。

现在,如果列表中的数据发生变化并且我尝试在发生异常后滚动 viewPager

java.lang.IllegalStateException: The application's PagerAdapter changed the adapter's contents without calling PagerAdapter#notifyDataSetChanged!
at android.support.v4.view.ViewPager.populate(Unknown Source)
            at android.support.v4.view.ViewPager.populate(Unknown Source)
            at android.support.v4.view.ViewPager.smoothScrollTo(Unknown Source)
            at android.support.v4.view.ViewPager.scrollToItem(Unknown Source)
            at android.support.v4.view.ViewPager.setCurrentItemInternal(Unknown Source)
            at android.support.v4.view.ViewPager.onTouchEvent(Unknown Source)
...
...
...

使用clone()方法从我传递给构造函数的ArrayList复制数据ViewPager's adapter 问题终于解决了