Created
November 10, 2018 08:16
-
-
Save mahdi-malv/77f8b2cf06f5233dbc9d81bde4f5b3e9 to your computer and use it in GitHub Desktop.
Detect double click on a view
This file contains hidden or 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
//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