How to handle double click on event onclicklistener in android studio? [duplicate]

北战南征 提交于 2021-01-29 08:33:49

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!