0

I want to detect in my app the touch of the user on the screen and reset some timer in this case. I found out that I can use onTouchEvent but it works only when I press free space without any button,.... I don't want to register touchEventListener on every View in my project. Is there some other way how to do it?

AdaMoOo
  • 427
  • 2
  • 5
  • 12

3 Answers3

1

Indeed, first you must override this method in your activity:

public boolean onTouchEvent(MotionEvent event);

Then, you have to disable action for your clickable elements.

Renaud Mathieu
  • 366
  • 2
  • 9
0

You should implement that OnTouchListener for the parent view and make child views non-clickable using setClickable(false)...

If that doesn't work you probably need to follow the method suggested in this answer

Community
  • 1
  • 1
Amit
  • 13,134
  • 17
  • 77
  • 148
0

all you have to do is to override onInterceptTouchEvent (MotionEvent ev) method in your top level container view or you can override Activity.onUserInteraction but it also includes key and trackball actions

pskink
  • 23,874
  • 6
  • 66
  • 77