I have an ImageView which fills my whole Activity. I need to be able to detect 4 touch events :
- Hold (longer than 400 ms)
- Click
- Swipe Left
- Swipe Right
At the moment I am able to detect the first two using the following code :
imageView.setOnTouchListener(new View.OnTouchListener() { private Timer timerr = new Timer(); private long LONG_PRESS_TIMEOUT = 400; // TODO: your timeout here private boolean wasLong = false; @Override public boolean onTouch(View v, MotionEvent event) { Log.d(getClass().getName(), "touch event: " + event.toString()); if (event.getAction() == MotionEvent.ACTION_DOWN) { // HOLD DETECTED timerr.schedule(new TimerTask() { @Override public void run() { SlideShow.this.runOnUiThread(new Runnable() { @Override public void run() { }, LONG_PRESS_TIMEOUT); return true; } if (event.getAction() == MotionEvent.ACTION_UP) { if (!isPaused && !wasLong) { // CLICK DETECTED timerr.cancel(); timerr = new Timer(); if (!wasLong) { return false; } }); Now I am trying to use the code from this question to implement the swipe right and swipe left actions. Android Swipe on List The problem with this is that this works on listview, where you can implement an onTouchListener for the whole listview, and a seperate onItemClickListener for the list item. I do not know how to adapt this to this situation though where only one Listener is available.