diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt index ff922e2e7..988a2fecf 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt @@ -462,11 +462,12 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View if (!isDestroyed) { pagerAdapter.shouldInitFragment = mPos < 5 view_pager.apply { + // must remove the listener before changing adapter, otherwise it might cause `mPos` to be set to 0 + removeOnPageChangeListener(this@ViewPagerActivity) adapter = pagerAdapter pagerAdapter.shouldInitFragment = true - currentItem = mPos - removeOnPageChangeListener(this@ViewPagerActivity) addOnPageChangeListener(this@ViewPagerActivity) + currentItem = mPos } } }