Last active
September 15, 2020 13:38
-
-
Save baggednismo/76888c6175630baa869bc2547290e5ec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
companion object { | |
private const val timerDelay: Long = 10 * 1000 // 10 seconds in milliseconds | |
} | |
override fun onCreate(savedInstanceState: Bundle?) { | |
... | |
pager.adapter = ViewPagerAdapter(updates) | |
... | |
pager.registerOnPageChangeCallback(object : OnPageChangeCallback() { | |
override fun onPageSelected(position: Int) { | |
super.onPageSelected(position) | |
val runnable = Runnable { pager.currentItem = position + 1 } | |
if (position < pager.adapter?.itemCount ?: 0) { | |
handler.postDelayed(runnable, timerDelay) | |
} | |
} | |
override fun onPageScrollStateChanged(state: Int) { | |
super.onPageScrollStateChanged(state) | |
/** | |
* The user swiped forward or back and we need to | |
* invalidate the previous handler. | |
*/ | |
if (state == SCROLL_STATE_DRAGGING) handler.removeMessages(0) | |
} | |
}) | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment