I tried implementing code from this question: Detecting a long press with Android, but it always detects a long press, if even I just tap it. My code is as follows (I extended ImageView
, because more code is in it, not relevant for this question):
public class EbsImageView extends ImageView {
final GestureDetector gestureDetector = new GestureDetector(this.getContext(), new GestureDetector.SimpleOnGestureListener() {
public void onLongPress(MotionEvent e) {
Log.e("", "Longpress detected");
}
public boolean onSingleTapUP(MotionEvent e) {
Log.e("", "Press detected");
// don't consume, we want the long press to fire if it was a
// long press
return false;
}
});
@Override
public boolean onTouchEvent(MotionEvent event) {
return gestureDetector.onTouchEvent(event);
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…