Android dispatchTouchEvent get listening

I call this function in my activity:

@Override public boolean dispatchTouchEvent(MotionEvent touchEvent) 

This allows me to process the action before any components are focused or even devoid of attention to these elements.

PROBLEM : I was wondering how I could know which component (view) was affected in this function, then I could choose whether I want to advise the event or not.

COAL DECISION . I currently have an ugly solution that: I know the position of the component that is allowed to receive the event, and I have enough to approximately solve the user clicked on this component.

Thanks.

+6
source share
2 answers

You probably want to use OnTouchListener

 private OnTouchListener mOnTouchListener= new OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { switch(v.getId()){ case R.id.id1): // Do stuff break; case R.id.id2: // Do stuff break; } return false/true; } }; 
0
source

view.getid == R.id.//id in the layout // the condition can be checked for clicking the desired view

0
source

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


All Articles