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

后端 未结 4 1406
孤独总比滥情好
孤独总比滥情好 2021-02-04 10:31

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 onScrollS

4条回答
  •  萌比男神i
    2021-02-04 11:09

    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.

提交回复
热议问题