Closed tomoyuki28jp closed 13 years ago
I found another issue. If there is only one row in ListView, the refresh view never disappear. Is this expected behavior?
When reaching the top it should bounce back. That's a bug.
Second issue I'm not sure, I do think that's expected at least that is how the Twitter implementation works which is our current reference.
Add the following code to onScroll(AbsListView, int, int, int) within PullToRefreshListView.java to fix the issue of the refresh view remaining visibly at the top after a fling scroll:
if ( mCurrentScrollState == SCROLL_STATE_TOUCH_SCROLL && mRefreshState != REFRESHING ) {
..
}
// add this code
else if ( mCurrentScrollState == SCROLL_STATE_FLING && firstVisibleItem == 0 ) {
scrollListTo( mRefreshViewHeight , 1250 );
}
EDIT: refined the code a little to take out unneeded statements
You can use the SCROLL_STATE_FLING to detect when a fling has occurred, and set a flag that you reset once SCROLL_STATE_FLING has ended. Place this in the onScroll as a conditional, and you will fix this issue. Also you will probably want to impement the same logic in a onTrackBallEvent and setOnKeyListener to make sure the user only fires this with a scroll rather d-pad or track ball.
To make this Android 2.1 compatible use setSelection(int) instead of smoothScrollBy. If you still want a smooth scrolling you can take the time to dispatch a TouchEvent, but this can get ugly. Sorry I haven't provided any code, if you have troubles implementing this yourself let me know and I'll finish it and upload the code.
EDIT: whoops, someone beat me to the SCROLL_STATE_FLING, must've missed this, should've refreshed comments before posting.
@mattg1981, @MantaMay Thank you, seems like SCROLL_STATE_FLING solves the problem with the view being visible. Will wrap it up during the weekend.
@MantaMay I've done some test with TouchEvent to simulate a smooth scroll, but never got it to behave as good as I wanted so I gave up and just used scrollBy if smoothScrollBy does not exist. Think it works fairly good but smooth scroll would be preferred though.
Instead of editing my previous post, I thought this was worthy of a new one. To make it feel even more like the Twitter Pull-To-Refresh (ie, on a fling, it is not visible at all when hitting the top, it is only visible when pulling the list down), make these adjustments:
if ( mCurrentScrollState == SCROLL_STATE_TOUCH_SCROLL && mRefreshState != REFRESHING ) {
mRefreshView.setVisibility( View.VISIBLE );
...
}
else if ( mCurrentScrollState == SCROLL_STATE_FLING && firstVisibleItem == 0 ) {
mRefreshView.setVisibility( View.GONE );
scrollListTo( mRefreshViewHeight , 1250 );
}
Hide the pull to fresh label in a fling, its now only visible when pulling the list down. Thank you mattg1981 and MantaMay for this. Closed by f69140d6ae9b69678c63b32735e85e8730e97992.
If we scroll fast once from the bottom and it stops on the top, the refresh view remain and nothing will happen.