Created
October 30, 2021 08:22
-
-
Save vamjakuldip/3567ad15532b248669e2dbbd59e5ef08 to your computer and use it in GitHub Desktop.
This class is used to prevent twice function issue on click event
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
class OnSingleClickListener(private val clickListener: View.OnClickListener, private val intervalMs: Long = 1000L) : View.OnClickListener { | |
private var canClick = AtomicBoolean(true) | |
override fun onClick(v: View?) { | |
if (canClick.getAndSet(false)) { | |
v?.run { | |
postDelayed({ | |
canClick.set(true) | |
}, intervalMs) | |
clickListener.onClick(v) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment