The documentation for the method getItemPosition in Android’s PagerAdapter class states that it is:
Called when the host view is attempting to determine if an item’s position has changed.
This method is supposed to be called to indicate whether or not an item’s position in the group of items for that adapter has changed.
However, it never states when an overriding method should consider the position to be changed. Does it mean the position is different to the position it was in last time the item getItemPosition was called? Does it mean the item’s position is different to last time notifyDataSetChanged was called? Or does it mean that the item’s position is different to when the item was added to the viewPager?
You can see in ViewPager.java that
getItemPositionis called only indataSetChanged. This means the item’s position changed if it’s different than the last timedataSetChangedwas called.I would not worry so much about the meaning of “changed”; there are two cases:
getItemPositionreturnsPOSITION_UNCHANGED;POSITION_UNCHANGEDor the actual position. So to keep the implementation simple you can return the position (orPOSITION_NONE) and forget aboutPOSITION_UNCHANGED..