Android Studio - How to perform doubleClick in Kotlin?

4.9k Views Asked by At

A boring thing when some more advanced technologies impose their standards is to have to do with the "double click" to perform an action. But what I'm looking for is an easy way to implement it without having to rewrite the code a thousand times.

I would like to implement double click in my project using Kotlin. Could someone help me? Thanks in Advance

just to know: I would like a way to understand how to do double click or to prevent that user do a doubleclick

3

There are 3 best solutions below

1
On BEST ANSWER

I implemented this library using Kotlin, you can just define the doubleClick property and override single and double click methods, and finally add it to setOnClickListener of your button

val doubleClick = DoubleClick(object : DoubleClickListener {
    override fun onSingleClickEvent(view: View?) {
        // DO STUFF SINGLE CLICK
    }

    override fun onDoubleClickEvent(view: View?) {
       // DO STUFF DOUBLE CLICK
    }
})

button.setOnClickListener(doubleClick)

https://gitlab.com/developerdeveloperdeveloper/androidutilslibrary

0
On

you can use this code its like double click if you dont like it you can read about Gesture Listener.

var doubleClick: Boolean? = false
yourview.setOnClickListener {
        if (doubleClick!!) {
            //Code here when they double click
        }
        doubleClick = true
        Handler().postDelayed({ doubleClick = false }, 2000)
       }
0
On

GestureDetector contains OnDoubleTapListener which allows us to handle double-clicks. It is the easiest way to implement a double-click listener. Also, you can try to find existing solutions like these:

https://github.com/pedromassango/doubleClick

https://github.com/fkirc/DoubleClickListener-for-Android

There are several posts on StackOverflow related to this theme. Please, check them.

how to implement double click in android

How to detect double click event for buttons in android

Double click event in android

According to clicks generating, I suppose you can call performClick() method several times with delay.