I have an events on swipe left and right on the screen but there is an invalid pointerId=-1 on TouchEvent that on some phones crashes the application here is the class i use
public class OnSwipeTouchListener implements OnTouchListener {
private final GestureDetector gestureDetector = new GestureDetector(new GestureListener());
@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
// TODO Auto-generated method stub
return gestureDetector.onTouchEvent(arg1);
}
private final class GestureListener extends SimpleOnGestureListener {
private static final int SWIPE_THRESHOLD = 100;
private static final int SWIPE_VELOCITY_THRESHOLD = 100;
@Override
public boolean onDown(MotionEvent e) {
return true;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
boolean result = false;
try {
float diffY = e2.getY() - e1.getY();
float diffX = e2.getX() - e1.getX();
if (Math.abs(diffX) > Math.abs(diffY)) {
if (Math.abs(diffX) > SWIPE_THRESHOLD && Math.abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) {
if (diffX > 0) {
onSwipeRight();
} else {
onSwipeLeft();
}
}
}
} catch (Exception exception) {
exception.printStackTrace();
}
return result;
}
}
public void onSwipeRight() {
}
public void onSwipeLeft() {
}
}
i get this error java.lang.IllegalArgumentException: pointerIndex out of range
in my main activity class i use this
fullView = (View)findViewById(R.id.fullview);
fullView.setOnTouchListener(imageViewSwiped); -> inside onCreate method
and after onCreate i use this
OnTouchListener imageViewSwiped = new OnSwipeTouchListener()
{
public void onSwipeRight() {
minusOne();
}
public void onSwipeLeft() {
// Toast.makeText(MainActivity.this, "left", Toast.LENGTH_SHORT).show();
plusOne();
}
};