android: AbsListView.OnScrollListener SCROLL_STATE_IDLE is not called after SCROLL_STATE_TOUCH_SCROLL (Version 2.1)
Asked Answered
P

4

12

I have a problem with android version 2.1. It looks like a bug.

I attached an OnScrollListener to my listView.

I'm using the method onScrollStateChanged(AbsListView view, int scrollState) for monitoring the scroll's state of my listview.

The scrollstate could assume 3 value (taken from the documentation):

  1. SCROLL_STATE_FLING: The user had previously been scrolling using touch and had performed a fling. The animation is now coasting to a stop
  2. SCROLL_STATE_IDLE:The view is not scrolling. Note navigating the list using the trackball counts as being in the idle state since these transitions are not animated.
  3. SCROLL_STATE_TOUCH_SCROLL:The user is scrolling using touch, and their finger is still on the screen

I assume that the SCROLL_STATE_IDLE will always be passed after one of other two states. It's always true excepted for android version 2.1. SCROLL_STATE_IDLE is not passed after SCROLL_STATE_TOUCH_SCROLL The problem happens also if you stop the fling by a touch instead of let the scroll stop by itself. This strange behaviour leaves my listView in an unconsistate state.

Someonelse has the same problem? Suggestion for a "not-so-dirty" work around?

Prosthodontist answered 9/6, 2010 at 12:41 Comment(0)
R
5

I think there is a bug that has been registered for this case.

http://code.google.com/p/android/issues/detail?id=5086

Reenareenforce answered 28/7, 2010 at 13:0 Comment(0)
R
2

I got a similar issue on 2.2.

If the list is big enough, and I scroll down up, I got first CROLL_STATE_TOUCH_SCROLL while my finger is on the screen. When my finger leave the screen I got the SCROLL_STATE_FLING. When my view has stopped moving I got the SCROLL_STATE_IDLE.

But, if during scroll, it reaches either View Top or Bottom, I only scroll/fling values and never the idle.

I checked out Shelves project from Romain Guy and his implementation suffer the same issue on 2.2.x I'm wondering if he had noticed yet.

I haven't tried yet with 2.3.x

Reversible answered 27/5, 2011 at 21:31 Comment(0)
S
2

I found something of a workaround for this (at least for API level 9+, where I'm still seeing the bug). I'm using a GridView, but I believe this should also work for ListView.

I'm using a subclass of GridView where I am detecting the overscroll (top or bottom):

 public class CustomGridView {
   private boolean mIsOverScrolled = false;

   @Override
   protected void onOverScrolled(int scrollX, int scrollY, 
                       boolean clampedX, boolean clampedY) {
     mIsOverScrolled = true;
     super.onOverScrolled(scrollX, scrollY, clampedX, clampedY);
   }

   public boolean isOverScrolled() {
     return mOsOverScrolled;
   }

   public void clearOverScroll() {
     mIsOverScrolled = false;
   }
 }

Then, in my OnScrollListener of CustomGridView, I have:

 @Override
 public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount,
                             int totalItemCount) {
   if (gridView.isOverScrolled()) {
     gridView.clearOverScroll();
   }

   // ...
 }

Now when I'm checking for OnScrollListener.SCROLL_STATE_IDLE, I also check if !gridView.isOverScrolled(). I'm not sure if that fixes your specific use cases, but hopefully you can use the additional piece of info to determine your current state despite the bug.

Snowfield answered 10/9, 2011 at 1:37 Comment(0)
C
0

I have had this same problem and posted a workaround on the bug list mentioned by DeRagan: Link

Caras answered 17/2, 2012 at 16:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.