0

I am using a ViewPager with a custom PagerAdapter to show a gallery. The gallery can receive a new object through the method onObjectReceived(); if the position of the new object is less than or equal to the current position, the current position of the gallery is updated to avoid the change of page.

ViewPager gallery;
PagerAdapter galleryAdapter;

@Override
public void onObjectReceived(Object object, int position) {
  if(galleryAdapter != null) {
      galleryAdapter.notifyDataSetChanged();
      if(position <= currentPosition)
          gallery.setCurrentItem(++currentPosition);
  }
}

Even if I am calling notifyDataSetChanged before setting the new position, I am getting the following exception:

IllegalStateException: The application's PagerAdapter changed the adapter's content without calling PagerAdapter#notifyDataSetChanged

at the line

gallery.setCurrentItem(++currentPosition);

How can I solve this problem?

P.S.: I have not overriden notifyDataSetChanged()

Alessandro Roaro
  • 4,665
  • 6
  • 29
  • 48

1 Answers1

-1

had similar problem. the notifyDataSetChanged only work if u can call in time.

for my case, similar to ur, it did not work for me by calling it right before I need the page changes. I solved it by creating a new adapter instance. not too happy about it but that worked.