Is there a way to get the direction of a Fling (up or down) in a ScrollListener attached to a ListView? I get the OnScrollListener.SCROLL_STATE_FLING without problems, but I can't get the direction. Do I have to write a whole GestureListener and onTouch listener and attach it to my ListView for this or is there an easier way? I just need the direction of the Fling nothing more. Thanks for your answers.
Asked
Active
Viewed 2,529 times
1
-
try [this code](http://stackoverflow.com/a/12115157/1000864) on stack overflow – Nayanesh Gupte May 17 '13 at 08:34
1 Answers
1
Do I have to write a whole GestureListener and onTouch listener and attach it to my ListView for this or is there an easier way?
You can simply use an OnTouchListener like this:
listView.setOnTouchListener(new OnTouchListener() {
int before = -1;
@Override
public boolean onTouch(View v, MotionEvent event) {
switch(event.getAction()) {
case MotionEvent.ACTION_DOWN:
before = ((ListView) v).getFirstVisiblePosition();
break;
case MotionEvent.ACTION_UP:
int now = ((ListView) v).getFirstVisiblePosition();
if(now < before)
Log.v("onTouch", "Scroll Up");
else if(now > before)
Log.v("onTouch", "Scroll Down");
}
return false;
}
});
If you only want to be notified when a fling happens: save the current scroll state in OnScrollListener's onScroll()
method and check if is a fling motion.

Sam
- 86,580
- 20
- 181
- 179