This piece of code does not work, I can not understand why. sv is SurfaceView, which is used to display the camera (this is for a note).

sv.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { if(motionEvent.getAction() == MotionEvent.ACTION_DOWN){ Toast.makeText(MainActivity.this, "onTouch", Toast.LENGTH_SHORT).show(); return true;}}}); 
  • I checked on the button - it works. Also onSwipeTouchListener is hung on this SurfaceView - and everything works fine, but View.OnTouchListener () does not want. What is the problem? - Nemezis16 pm

2 answers 2

Try another event.

  sv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(View.getContext(), "Clicked", Toast.LENGTH_SHORT).show(); Log.v("W", "Clicked"); }); 
  • That doesn't work either ... strange - Nemezis16
  • If even in logcat does not write clicked, then you need to look at the rest of the code. - igumnov
  • But can several OnTouchListeners be hanged on one object? - Nemezis16
  • You can probably, but most likely the one that is specified in the last call to setOnTouchListener will be used. - igumnov
  • one
    SimpleOnGestureListener onFling method (MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) - igumnov

Made a list based on a ListView . We needed свайпы , скрол and *синглтачи* . I did not want to use or customize any GestureDetector s.

But simultaneously hanging several *листенеров* on one view ended only with the fact that you had to make crutches that are much harder than any GestureDetector .

Therefore, I had to hang on the OnTouchListener OnTouchListener , from the onTouch method onTouch transfer the touch event to the GestureDetectorCompat , and in its onScroll method onScroll implemented the logic of the *свайпа* . *Синглтачи* handled with the same `GestureDetectorCompat.