I've tried a lot of solutions but couldn't find anything that worked. Each element in my List view takes up the whole screen. I would like to navigate from one element to the next by using a vertical swipe gesture. My current setup right now has free scrolling, but I would like to disable this and allow only for vertical up and down swipes. Each swipe (depending on the direction) should bring me to the next consecutive element in the list view and snap into place.
Here is my current code:
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
// TODO Auto-generated method stub
switch (scrollState) {
case OnScrollListener.SCROLL_STATE_IDLE:
if (scrolling){
// get first visible item
RelativeLayout item = (RelativeLayout) view.getChildAt(0);
int top = Math.abs(item.getTop()); // top is a negative value
int botton = Math.abs(item.getBottom());
if (top >= botton){
//((ListView)view).setSelectionFromTop(view.getFirstVisiblePosition()+1, 0);
((ListView)view).smoothScrollToPositionFromTop(view.getFirstVisiblePosition()+1, 0, 1);
} else {
((ListView)view).smoothScrollToPositionFromTop(view.getFirstVisiblePosition(), 0, 1);
}
}
scrolling = false;
break;
case OnScrollListener.SCROLL_STATE_TOUCH_SCROLL:
case OnScrollListener.SCROLL_STATE_FLING:
scrolling = true;
break;
}
}
How can I go about achieving this?