Is there a way to identify if listview is being scroll up or down?
OnScrollListener doens't help me in this case.
Thanks in advance!
Is there a way to identify if listview is being scroll up or down?
OnScrollListener doens't help me in this case.
Thanks in advance!
There is a method in
ScrollViews
that reports the shifting of scrolls. It is calledonScrollChanged()
. However, it is declared protected, so you must create a wrapper class to gain access. For the usage of the method, please check android docs.First, create an interface to expose the protected method
Then, create your wrapper and extend ScrollView
Finally, include it in your XML layout like a custom view, and attach listeners like usual.
for whom ever still looking for an answer for kotlin, this works for it
Uncomment to use an alternative method.
An easy and working solution.
this is a simple implementation:
The solution given by Some Noob Student is good: you have to create a wrapper to use the protected onScrollChanged(int x, int y, int oldx, int oldy) method, which is triggered more often then the standard AbsListView.OnScrollListener.onScrollStateChanged(AbsListView view, int scrollState).
Unfortunately the onScrollChanged() always returns 0 as parameters, no matter how I scroll, and seems to detect only when the scroll ends, reaching the top or the bottom of the list.
So I used the following code to detect the right direction of the scrolling: it uses the getTop() of the first visible item but uses also its position to understand when the first item is no more visible; during this item transition, the scroll direction is given by the item position itself.
Here based on the last visible item i decide whether the list is going up or down