Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: ScrollView 'setOnScrollListener' (like ListView)

Tags:

android

I want to do something when the user has scrolled >90% down, so I thought I could just add a onScrollListener like I would in a ListView. Unfortunatly, ScrollView doesn't seem to have a similar method. Is there any way I can do what I want; getting a notification when the user scrolls approx 90% down?

Thanks, Erik

like image 360
Erik Avatar asked Aug 18 '10 15:08

Erik


2 Answers

This is what I end up doing to know if the user was interacting with my ScrollView or not:

findViewById(R.id.scrollview).setOnTouchListener(new View.OnTouchListener() {

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        switch (event.getAction()) {
        case MotionEvent.ACTION_SCROLL:
        case MotionEvent.ACTION_MOVE:
            setScrollState(OnScrollListener.SCROLL_STATE_FLING);
            break;
        case MotionEvent.ACTION_DOWN:
            setScrollState(OnScrollListener.SCROLL_STATE_TOUCH_SCROLL);
            break;
        case MotionEvent.ACTION_CANCEL:
        case MotionEvent.ACTION_UP:
            setScrollState(OnScrollListener.SCROLL_STATE_IDLE);
            break;
        }
        return false;
    }
});
like image 117
mmathieum Avatar answered Sep 27 '22 19:09

mmathieum


You can try extending ScrollView and overriding View#onScrollChanged and the doing your checks there. You have to extend ScrollView since onScrollChanged is a protected method.

like image 40
Rich Schuler Avatar answered Sep 27 '22 17:09

Rich Schuler