Skip to content

Instantly share code, notes, and snippets.

@titoaesj
Created March 20, 2018 12:10
Show Gist options
  • Save titoaesj/5bf52547ce779c6987dc24bc5a52fb64 to your computer and use it in GitHub Desktop.
Save titoaesj/5bf52547ce779c6987dc24bc5a52fb64 to your computer and use it in GitHub Desktop.
class CustomDisableSwapViewPager(context: Context, attrs: AttributeSet) : ViewPager(context, attrs) {
var enabled: Boolean?
init {
this.enabled = false
}
override fun onTouchEvent(event: MotionEvent): Boolean {
return if (this.enabled!!) {
super.onTouchEvent(event)
} else false
}
override fun onInterceptTouchEvent(event: MotionEvent): Boolean {
return if (this.enabled!!) {
super.onInterceptTouchEvent(event)
} else false
return super.isClickable()
}
fun isSwipEnabled(enabled: Boolean) {
this.enabled = enabled
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment