1

I am developing an android application which has a scrollview. I have overriden my view from ScrollView and have implemented the onScrollChanged method. As the scrollview scrolls and reaches the bottom, it loads more products and add them to scrollvew. I am having a strange issue. First time when products loads and I try to drag up the scrollview, onScrollChanged never happens. Then I googled and found something:

scrollView.setOnTouchListener(new ListView.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            int action = event.getAction();
            switch (action) {
            case MotionEvent.ACTION_DOWN:
                // Disallow ScrollView to intercept touch events.
                v.getParent().requestDisallowInterceptTouchEvent(false);
                break;

            case MotionEvent.ACTION_UP:
                // Allow ScrollView to intercept touch events.
                v.getParent().requestDisallowInterceptTouchEvent(true);
                break;
            }

            // Handle ListView touch events.
            v.onTouchEvent(event);
            return true;
        }
    });

After adding this, when I try to drag the scrollview from empty area of scrollview, it starts to call onScrollChanged and afterwards I start dragging from anywhere else, onScrollChanged is being called. My question is, why it is behaving like that? It should call onScrollChanged from whatever the touch event starts. I hope, I explained my point well. Any solution?

Khawar Raza
  • 15,870
  • 24
  • 70
  • 127
  • So you're disabling scroll on press and reeanbling it. Why? – Radu Aug 19 '14 at 10:41
  • I am not disabling scroll at any time. When first time contents load, scroll does not work except I start scroll from an empty area. Empty in the sense that there is not child. When I scroll by touching any child, it does not but only for first time. After scroll starts, everything gets normal. – Khawar Raza Aug 19 '14 at 12:26
  • what do you call requestDisallowInterceptTouchEvent. – Radu Aug 19 '14 at 13:32

1 Answers1

1

Why don't you use endless adapter with a view like ListView or GridView to achieve the desired behavior instead

elmorabea
  • 3,243
  • 1
  • 14
  • 20
  • First, I have some custom UI requirements that cannot be fulfilled using listview or gridview. Second, endless adapter has very overhead work which I dont want to add in my app. I am looking for some workaround using the scrollview. – Khawar Raza May 21 '14 at 19:08
  • check this link out http://stackoverflow.com/questions/8181828/android-detect-when-scrollview-stops-scrolling – elmorabea May 21 '14 at 19:11
  • Friend, please read my question. I am not concerned with when scroll starts or ends. I just want that whenever user scrolls, it should scroll whatever user taps or starts dragging. – Khawar Raza May 21 '14 at 19:51