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()