Count the Number of Taps (Multi-Tapping) on a View in Android
In this article, the number of taps that user does in a short span of time on a particular view is counted, It can be used for adding different response with different taps. For example one tap on the word will show the meaning of the word while double tap will show its synonyms in a dictionary app. Below is an example in which the number of taps done in textview is shown as a 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 triple tap is added with it.
Step 3: In this step add the onTouchListenter with the view. Here in the listener initialize a variable to 0 which will keep the count of taps user has done. Every time user taps in a short span of time the variable value is increased by one. Below is the code for the MainActivity.kt class.
Please Login to comment...