问题
Please help How to handle the double click on event OnClicklistener
on the button, Cardview or others,
回答1:
Please try below:-
Java Version:-
private var doubleClickLastTime = 0L
view.setOnClickListener {
if(System.currentTimeMillis() - doubleClickLastTime < 300){
doubleClickLastTime = 0
doAction()
}else{
doubleClickLastTime = System.currentTimeMillis()
}
}
Kotlin Version:-
val doubleClickLastTime = 0L
view.setOnClickListener
run({ if (System.currentTimeMillis() - doubleClickLastTime < 300)
{
doubleClickLastTime = 0
doAction()
}
else
{
doubleClickLastTime = System.currentTimeMillis()
} })
来源:https://stackoverflow.com/questions/57212171/how-to-handle-double-click-on-event-onclicklistener-in-android-studio