Easy way to keep the listeners working while touching the screen

63 views Asked by At

Here is my scenario: a LinearLayout as the main layout of the Activity. The Layout contains an ImageView which has its own onClickListener.

What would be the easiest way to fire the ImageView listener while the user rests his finger on the screen. This is a general scenario where the user is holding the device and touches the screen by mistake(so a onTouch fires) but wants to press the ImageView. In this case, since the screen is already touched, when pressing he ImageView, nothing happens.

enter image description here

1

There are 1 answers

1
Akhil On BEST ANSWER

I guess you can achieve same by using ACTION_DOWN & ACTION_POINTER_DOWN, where later is for second touch. You need to handle these events in your touchlistner. This listener can be on your root layout.

public boolean onTouchEvent(MotionEvent event) {
}

See here, some excerpts are :

When multiple pointers touch the screen at the same time, the system generates the following touch events:
ACTION_DOWN—For the first pointer that touches the screen. This starts the gesture. The pointer data for this pointer is always at index 0 in the MotionEvent.
ACTION_POINTER_DOWN—For extra pointers that enter the screen beyond the first. The pointer data for this pointer is at the index returned by getActionIndex().
ACTION_MOVE—A change has happened during a press gesture.
ACTION_POINTER_UP—Sent when a non-primary pointer goes up.
ACTION_UP—Sent when the last pointer leaves the screen.