Skip to content

Instantly share code, notes, and snippets.

@mahdi-malv
Created November 10, 2018 08:16
Show Gist options
  • Save mahdi-malv/77f8b2cf06f5233dbc9d81bde4f5b3e9 to your computer and use it in GitHub Desktop.
Save mahdi-malv/77f8b2cf06f5233dbc9d81bde4f5b3e9 to your computer and use it in GitHub Desktop.
Detect double click on a view
//Double click detection
var timeSaver = 0L // Globaly
view.setOnTouchListener { _, event ->
when(event.action) {
MotionEvent.ACTION_DOWN -> {
if (System.currentTimeMillis() - timeSaver <= 500) {
// Do with double click
Toast.makeText(this, "DOUBLE_CLICK", Toast.LENGTH_SHORT).show()
}
timeSaver = System.currentTimeMillis()
true
}
else -> false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment