1

I would like to listen to if list view is scrolling from bottom to up.

I have tried many work around's but couldn't get the logic for this. The answer on this post did not help me either and also answer on this post helped me to detect if listView is scrolled, (no idea weather it's top to bottom or bottom to top). Can any one help me to detect if list view is scrolled up (bottom to up)

Thanks.

Community
  • 1
  • 1
Wesley
  • 1,808
  • 5
  • 31
  • 46

1 Answers1

3

I've edited the snippet from the second post:

public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
    if(currentFirstVisibleItem > firstVisibleItem){
        //scrolling to top of list
    }else if (currentFirstVisibleItem < firstVisibleItem){
        //scrolling to bottom of list
    }

    this.currentFirstVisibleItem = firstVisibleItem;
    this.currentVisibleItemCount = visibleItemCount;        
}
nhaarman
  • 98,571
  • 55
  • 246
  • 278
  • Niek, there seems to be problem, If I set a log in both (if and else) statements, both gets executed randomly. Since onScroll is called every time when the list is even moved a pixel, else part is read even when list is scrolled to top. if part is read only when a new view is recycled. – Wesley Jul 02 '12 at 12:31
  • I thought it was called when a new item was shown. Anyway, try the edited snippet. This way you ignore the calls to onScroll() where the first item stays the same. – nhaarman Jul 02 '12 at 13:06
  • Yes that works. :) but now I'm running into a new problem. That's with a pretty different issue in translate animations of a view out and in. – Wesley Jul 02 '12 at 13:58