0

Please help How to handle the double click on event OnClicklistener on the button, Cardview or others,

Shalu T D
  • 3,921
  • 2
  • 26
  • 37
  • 1
    Checkout this, https://stackoverflow.com/questions/4849115/implement-double-click-for-button-in-android – taug Jul 26 '19 at 01:58

1 Answers1

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()
     } })
Shalu T D
  • 3,921
  • 2
  • 26
  • 37