Created
December 26, 2013 07:34
-
-
Save kyze8439690/8130871 to your computer and use it in GitHub Desktop.
OnScrollListener to detect scrollup and scrolldown in ListView.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ListViewOnScrollListener extends OnScrollListener{ | |
@Override | |
public void onScrollStateChanged(AbsListView view, int scrollState) {} | |
private int lastVisibleItem = 0; | |
private int lastY = 0; | |
@Override | |
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { | |
int top = 0; | |
if(view.getChildAt(0) != null){ | |
top = view.getChildAt(0).getTop(); | |
} | |
if(firstVisibleItem > lastVisibleItem){ | |
//scroll down | |
}else if(firstVisibleItem < lastVisibleItem){ | |
//scroll up | |
}else{ | |
if(top < lastY){ | |
//scroll down | |
}else if(top > lastY){ | |
//scroll up | |
} | |
} | |
lastVisibleItem = firstVisibleItem; | |
lastY = top; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment