I had some confusion about how onTouchEvent () and onTouch () work (you can see my comment on this question). After some research below, I found out about this. This may be useful for beginners.
1) Implementation:
If you want to use onTouch (), you need to do three things.
1- implement OnTouchListener
2- call setOnTouchListener () in the view you want to set in order to catch the event
3- override onTouch () to handle the event
but if you want to use onTouchEvent (), you do not need to do steps 1 and 2 above. you just need to override onTouchEvent ().
2) Work:
onTouch () works in the view, view, activity mode. This means that you can use onTouch () inside a view, viewgroup or activity. These methods take two arguments [onTouch (View v, MotionEvent e)]. This allows you to filter events for different views in an action or view group. Or the activity itself can handle it. onTouchEvent () takes one argument [ onTouchEvent(MotionEvent e)
]. Thus, this can only be used inside a view that implements it or in a derived form. The derived view allows you to extend the touch behavior defined in onTouchEvent ().
I think that such options are part of a more flexible Android development philosophy, although sometimes this creates confusion for students.
Dexter Apr 13 '14 at 13:27 2014-04-13 13:27
source share