Reputation: 166
I have tableview on android app. I need to enable delete button when we swipe from left-to-right or right-to-left on table row and need to disable button when we click anywhere on screen. It should work from 2.3 to jellybean. Please provide me solution for this.
Upvotes: 0
Views: 2248
Reputation: 3004
Such option is called FLING in android...
Check is sample: https://github.com/krishjlk/android-listview-swipe-delete-example-sample-tuorial
May help
EDIT :
private class GestureListener extends SimpleOnGestureListener {
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
System.out.println("UFFFFF");
if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
System.out.println("Right to left");
return false; // Right to left
} else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
System.out.println("Left to right");
iv5.setBackgroundDrawable(enterShape);
Intent go=new Intent(Swipe.this,NewContact.class);
startActivity(go);
return false; // Left to right
}
if (e1.getY() - e2.getY() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) {
return false; // Bottom to top
} else if (e2.getY() - e1.getY() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) {
return false; // Top to bottom
}
return false;
}
}
Upvotes: 4