Skip to content

Instantly share code, notes, and snippets.

@baggednismo
Created September 15, 2020 14:28
Show Gist options
  • Save baggednismo/0e6823caf6026d9ecf99f3b8fceb3b9f to your computer and use it in GitHub Desktop.
Save baggednismo/0e6823caf6026d9ecf99f3b8fceb3b9f to your computer and use it in GitHub Desktop.
override fun onCreate(savedInstanceState: Bundle?) {
...
btnContinue.setOnClickListener {
if (pager.currentItem < pager.adapter?.itemCount!! - 1) {
handler.removeMessages(0)
pager.currentItem = ++pager.currentItem
}
}
// I expect the back button to be hidden when ViewPager2 is at position 0
btnBack.setOnClickListener { onBackPressed() }
...
}
override fun onBackPressed() {
if (pager.currentItem == 0) super.onBackPressed()
else {
handler.removeMessages(0)
pager.currentItem = --pager.currentItem
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment