2

can anyone tell me why I can not get onOverScrolled be called in my following code:

   public class KasOverScrollListenableListView extends ListView {

    public interface OverScrollListener{
        void onOverScroll(int scrollx, int scrollY,boolean clampedX, boolean clampedY );
    }
    private OverScrollListener mOverScrollListener= null;
    public KasOverScrollListenableListView(Context context, AttributeSet attrs,
            int defStyle) {
        super(context, attrs, defStyle);
    }

    public KasOverScrollListenableListView(Context context, AttributeSet attrs){
        this(context,attrs,0);
    }

    public KasOverScrollListenableListView(Context context){
        this(context,null,0);
    }

    protected void onOverScroll(int scrollX, int scrollY, boolean clampedX, boolean clampedY){
         Log.i("overScrolling", "overScrolling is " + scrollY);
        // if the version of the system higher than 2.3 then do the following things.
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD){
//          super.onOverScrolled(scrollX, scrollY, clampedX, clampedY);
            if(null != mOverScrollListener ){
                mOverScrollListener.onOverScroll(scrollX, scrollY, clampedX, clampedY);
            }
        }

    }

    public void setOnOverScrollListener(OverScrollListener listener){
        mOverScrollListener = listener;
    }
}

I can never get the log to be output which means this function never been called, while this listview is actually overscrolled.I will really be grateful to hear your idea.

gothion
  • 125
  • 1
  • 10
  • which Android are you using? – Sagar Nov 29 '12 at 08:17
  • 1
    To use "onOverScroll()" you need API level 9 or above. onOverScrolledBy() method calls this method as a result of overscrolling operation. If you are using Android 2.2 it will not work, tryusing Android 2.3 ie API level 9. – Sagar Nov 29 '12 at 08:24
  • Thanks for your reply. I'm using the API higher than 9. I just want to listen to the overScrolling of android,but fails to find a way.it seems that the overwritten function onOverscroll() has never been called,I'am just really confusing about this. – gothion Dec 03 '12 at 01:16
  • Try Adding annotation "@Override" above onOverScrolled() method. May work. – Sagar Dec 05 '12 at 12:11
  • Hi gothion...have you found a solution to your problem?...I am facing the issue using a samsung 3.1 device. My suspicions are that samsung messed up this feature after the whole apple patent lawsuit ordeal...would really appreciate it if you could let me in on the solution.. – Houston Mar 05 '13 at 16:20
  • Hi,Houston,I'm sorry that I havent't found a solution, further I have found that the overscrolling like thing happens in a samsung pad ,with android 2.2 it's os. – gothion Mar 07 '13 at 12:29

3 Answers3

1

Not sure if this will help, but the example in the below link calls super.overScrollBy(...). I am able to get to onOverScroll using this code. Hope it helps...

OverScroll ListView Sample code

Aviral
  • 1,141
  • 1
  • 10
  • 16
0

Just...if it will needed someone. I shared working sample on Github.

Works fine on 2.3+

0

The method is onOverScrolled, not onOverScroll.

You can detect these bugs by putting @Override above the method signature. The compiler will let you know if you really are overriding a method or not.

Kacy
  • 3,330
  • 4
  • 29
  • 57