Expanding on another Stackoverflow question, I\'ve implemented some gesture detection code so that I can detect when a row in my listview (which is in a FrameLayout) has bee
I implemented something like this in my app once. The way I did it:
public class MyGestureDetector extends SimpleOnGestureListener {
private ListView list;
public MyGestureDetector(ListView list) {
this.list = list;
}
//CONDITIONS ARE TYPICALLY VELOCITY OR DISTANCE
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
if (INSERT_CONDITIONS_HERE)
if (showDeleteButton(e1))
return true;
return super.onFling(e1, e2, velocityX, velocityY);
}
private boolean showDeleteButton(MotionEvent e1) {
int pos = list.pointToPosition((int)e1.getX(), (int)e1.getY());
return showDeleteButton(pos);
}
private boolean showDeleteButton(int pos) {
View child = list.getChildAt(pos);
if (child != null){
Button delete = (Button) child.findViewById(R.id.delete_button_id);
if (delete != null)
if (delete.getVisibility() == View.INVISIBLE)
delete.setVisibility(View.VISIBLE);
else
delete.setVisibility(View.INVISIBLE);
return true;
}
return false;
}
}
This worked for me, hope you'll get it to work or that it at least gives you some hint.