Update: See bounty for expanded question.
I have a GestureDetector
setup on a ListView
. The ListView is an entire fragment that comes from side of window and overlays another fragment partially. I want to give user ability to swipe it close (i.e. Wunderlist is a great example of this function on right side).
Here is my setup:
gestureListener = new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (gestureDetector.onTouchEvent(event)) {
return true;
}
return false;
}
};
listView.setOnTouchListener(gestureListener);
The Listener itself:
public class GestureListener extends SimpleOnGestureListener {
private static final int SWIPE_MIN_DISTANCE = 180;
private static final int SWIPE_THRESHOLD_VELOCITY = 50;
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
try {
if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
FragmentManager fma = getActivity()
.getSupportFragmentManager();
FragmentManager fm = getFragmentManager();
FragmentTransaction t = fm.beginTransaction();
SherlockListFragment mFrag = new RateReviewFragment();
t.add(R.id.main_frag, mFrag);
t.setCustomAnimations(R.anim.animation_enter,
R.anim.animation_leave);
t.remove(mFrag);
t.commit();
}
return false;
} catch (Exception e) {
}
return false;
}
@Override
public void onLongPress(MotionEvent e) {
// edited out; this opens up a context menu
}
}
Sometimes, when the ListView
scrolls to the bottom (or list scrolling is interrupted with clicks on a list row) the GestureListener
simply stops ... listening. Swiping will not work. You have to scroll back to top to get it to work again.
If anyone can help me isolate these issues I would be grateful!
UPDATE : Only one issue remains, "the listener stops listening"
UPDATE TWO: I may have figured out what is CAUSING this; just dont know the fix:
I have found something out after logging my actions; The lower I get in the list (and the more I interact with it), the measurements are not consistent. For example, if I move my finger a centimeter left and right - at very top of list, it will say I moved, for example, 200 pixels. But when I have the problem stated above, it is far lower, maybe 50, for the SAME 1 centimeter distance. So the window doesn't close because it's not meeting my if
conditions.
Sidenote: I have stated more than once, the problem is when "interacting with the list". This means: If I quickly scroll from top to bottom; no issue; but If I slowly work my way down, perhaps tapping on the screen, scrolling on and off, clicking buttons on the listView
, some of which open a new activity (and then come back to same position), this is "interacting" with".