What is the difference between a view's onTouchEvent
:
public class MyCustomView extends View {
// THIS :
@Override
public boolean onTouchEvent(MotionEvent event) {
return super.onTouchEvent(event);
}
}
and its onTouchListener
:
MyCustomView myView = (MyCustomView) findViewById(R.id.customview);
myView.setOnTouchListener(new View.OnTouchListener() {
@Override
public void onClick(View arg0) {
// do something
}
});
or
public class MyCustomView extends View {
public MyCustomView(Context context, AttributeSet attrs) {
// THIS :
setOnTouchListener(new View.OnTouchListener() {
@Override
public void onClick(View arg0) {
// do something
}
});
}
@Override
public boolean onTouchEvent(MotionEvent event) {
return super.onTouchEvent(event);
}
}
If this two is different,
Do we need to implement both ?
Which one is invoked first ?
If I have some scrolling and zooming functionality, should I implement them inside onTouchEvent
or onTouchListener
?