how to implement double click in android

前端 未结 9 812
深忆病人
深忆病人 2020-12-05 20:36

I am doing a project in which i want to display a particular message on single touch and another message on double touch using android.How can i implement it.

My sa

9条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-05 21:22

    You may employ RxAndroid in that case in Kotlin it shall be like this:

    yourView.clicks().buffer(500, TimeUnit.MILLISECONDS, 2).filter {
        it.size >= 2
    }.subscribe {
        // Handle double click
    }
    
    1. We apply clicks() extension function on a given view which creates an RX observable sequence.
    2. We tell RX to emit an event after either 500 ms or 2 consecutive clicks take place within 500 ms.
    3. We tell RX to take only the events only with 2 consecutive click
    4. Last but not least we subscribe to the event sequence which is our DoubleClick handler

提交回复
热议问题