Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2012
2,774
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. How to detect if a listview is scrolling up or down in android?
  2. public interface OnScrollListener {
  3. void onScrollChanged(int x, int y, int oldx, int oldy);
  4. }
  5.  
  6. public class ReportingScrollView extends ScrollView {
  7. private OnScrollListener onScrollListener = null;
  8.  
  9. public ReportingScrollView(Context context) {
  10. super(context);
  11. }
  12.  
  13. public ReportingScrollView(Context context, AttributeSet attrs, int defStyle) {
  14. super(context, attrs, defStyle);
  15. }
  16.  
  17. public ReportingScrollView(Context context, AttributeSet attrs) {
  18. super(context, attrs);
  19. }
  20.  
  21. public void setOnScrollListener(OnScrollListener onScrollListener) {
  22. this.onScrollListener = onScrollListener;
  23. }
  24.  
  25. @Override
  26. protected void onScrollChanged(int x, int y, int oldx, int oldy) {
  27. super.onScrollChanged(x, y, oldx, oldy);
  28. if (onScrollListener != null) {
  29. onScrollListener.onScrollChanged(x, y, oldx, oldy);
  30. }
  31. }
  32. }
  33.  
  34. <your.package.ReportingScrollView />
  35.  
  36. scrollingandtrolling.setOnScrollListener(new OnScrollListener() {...});
Advertisement
RAW Paste Data Copied
Advertisement