Android Touch event on screen

I want to find out an event when a user touches any android screen. I recognize a touch event for a specific activity, but not for all screens, please give me a Solution.

+6
source share
4 answers

try this code

@Override public boolean onTouchEvent(MotionEvent event) { // TODO Auto-generated method stub return super.onTouchEvent(event); } 
+20
source

The problem that can occur when using onTouchEvent() is that because of your view hierarchy, in which you also have other views on top of your activity, it concerns views that override this event (buttons, edittext, etc. .) will not decline; you no longer need activity, and you will not receive them.

Instead, you should use dispatchTouchEvent() , as it spreads differently, from activity to your other views, and is always called.

 @Override public boolean dispatchTouchEvent(MotionEvent ev) { // Your code here return super.dispatchTouchEvent(ev); } 
+11
source

The touch android event is dispatched by level, begins with activity in the viewing group and presentation. such as Activity - RelativeLayout - Button, there are many override methods that can handle touch events. It can help you.

0
source

I do not think that's possible.

You can use an additional class that receives all sensory events from all your actions. To do this, you need to implement the walkthrough in each action.

 publich class TouchStore(){ public void recieveTouchEvent(MotionEvent event){ //Handle your events } } public boolean onTouchEvent(MotionEvent event) { touchStore.recieveTouchEvent(event); } 
-1
source

Source: https://habr.com/ru/post/885790/


All Articles