Double-Tap on a View in Android Last Updated : 18 Feb, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report Detecting a double tap i.e. whenever the user double taps on any view how it is detected and according to the view a response can be added corresponding to it. Here an example is shown in which the double tap on the view is detected and corresponding to it a response is added in the form of toast. Step 1: Create an Empty activity in Android Studio. To create one, follow this article- https://www.geeksforgeeks.org/android-how-to-create-start-a-new-project-in-android-studio/. Check if the primary language selected is Kotlin. Step 2: No change is done in activity_main.xml. Since already a textview is present so the response for the double tap is added with it. XML <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <TextView android:id="@+id/tvView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" /> </androidx.constraintlayout.widget.ConstraintLayout> Step 3: In this step add the abstract class for the double tap and set the onClickListener which will use the abstract class. Below is the code for the MainActivity.kt class. Kotlin package org.geeksforgeeks.viewdoubletap import android.os.Bundle import android.view.View import android.widget.TextView import android.widget.Toast import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) // In our case, we tap on Text View val view = findViewById<TextView>(R.id.tvView) // Double Click Listener implemented on the Text View view.setOnClickListener(object : DoubleClickListener() { override fun onDoubleClick(v: View?) { Toast.makeText(applicationContext,"Double Click",Toast.LENGTH_SHORT).show() } }) } // Abstract class defining methods to check Double Click where Time Delay // between the two clicks is set to 300 ms abstract class DoubleClickListener : View.OnClickListener { var lastClickTime: Long = 0 override fun onClick(v: View?) { val clickTime = System.currentTimeMillis() if (clickTime - lastClickTime < DOUBLE_CLICK_TIME_DELTA) { onDoubleClick(v) } lastClickTime = clickTime } abstract fun onDoubleClick(v: View?) companion object { private const val DOUBLE_CLICK_TIME_DELTA: Long = 300 //milliseconds } } } Output on the Emulator: Comment More infoAdvertise with us Next Article How to add ViewFlipper in android? A aashaypawar Follow Improve Article Tags : Android Android-View Similar Reads Double-Tap on a Button in Android Detecting a Double Tap on Button in Android i.e. whenever the user double taps on any Button how it is detected and according to the Button a response can be added corresponding to it. Here an example is shown in which the double tap on the Button is detected and the corresponding to it response is 3 min read PopView in Android In this article, PopView is added to android. When users tap on the view a pop animation with a circular dust effect will appear. A new view can also appear after the popping of the older view. PopView can be used to hide the view or change the view. It makes the user interface more attractive. Supp 3 min read How to Implement OTP View in Android? An OTP View or PinView in android is a widget that allows users to enter their PIN, OTP, etc. They are generally used for two-factor authentication or phone number verification by OTP. A sample video is given below to get an idea about what we are going to do in this article. Note: In order to imple 2 min read View Binding in Android Jetpack View Binding is one of the best features in Android that allows views to bind seamlessly with an ongoing activity. It replaces the traditional findViewById()method, significantly reducing boilerplate code by automatically generating instances of views for the current layout. One of its most importan 3 min read How to add ViewFlipper in android? This article is about the implementation of ViewFipper in android. It is an extension of the ViewAnimator class which helps to animate between views added to it. ViewFlipper makes it easy to switch view. To control over flipping between views ViewFlipper provides two methods startFlipping() and stop 3 min read Ball Tapping Game in Android Android is an open-source operating system, based on the Linux kernel and used in mobile devices like smartphones, tablets, etc. Further, it was developed for smartwatches and Android TV. Each of them has a specialized interface. Android has been one of the best-selling OS for smartphones. Android O 4 min read Like