Implementing the double tap on an ImageView

In this post I explain a simple example of an implementation of a double tap event on an ImageView that can be adapted with some changes for a TextView or an Activity.

    1., the main activity
    2. res/layout/activity_main.xml, il layout per l’activity principale

      at the line 8 there is a View linked to the class DoubleTapView that extends an ImageView

    at the line 17 the method onDoubleTap handles the double tap but you need the following four important points:

    • line 34: creation of an object of the class GestureDetectorCompat (mDetector)
    • line 13: the inner class that extends GestureDetector.SimpleOnGestureListener and an object of this class is passed as argument to the constructor of mDetector of the previous point
    • line 38: the method onTouchEvent of ImageView is overridden and calls onTouchEvent of GestureDetectorCompat (mDetector)
    • line 23: in the inner class that extends GestureDetector.SimpleOnGestureListener the method onDown is overridden and returns true

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.