0

I'm working on a code at android for applying a form and before completing it, user has to accept a policy. If i put a TextView inside of ScrollView and a button for accepting, user can accept directly before read. But i must force user to scroll to bottom and then make Accept button became enabled and user accepts it then continue. First i tried this inside of Dialog Window. It's getting much more complicating. Now I'm trying it to inside another activity.

Is there any way to detect Scroll View's position has reached to end ?

Kuroiteiken
  • 188
  • 1
  • 14

3 Answers3

0

You can use the canScrollVertically method with a setOnScrollChangeListener, exemple :

 scrollView.setOnScrollChangeListener(new View.OnScrollChangeListener() {
            @Override
            public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
                if (scrollView.canScrollVertically(1)) {
                    //user can't scroll more in bottom direction
                }
            }
        });

If the canScrollVertically is reach the user is in the bottom of the scrollView and can't scroll more. If you put a negative value like -1 the method detect if the user can scrolling up

Vodet
  • 1,235
  • 15
  • 32
0

You can detect it via below code

scrollView.getViewTreeObserver()
    .addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() 
{
        @Override
        public void onScrollChanged() {
            if (scrollView.getChildAt(0).getBottom()
                 <= (scrollView.getHeight() + scrollView.getScrollY())) {
                //scroll view is at bottom
            } else {
                //scroll view is not at bottom
            }
        }
    });
sohel.eco
  • 223
  • 1
  • 10
0
  1. Fragments automatically save and restore the states of their Views, as long they have IDs assigned to it. By Assiging an Id(android:id) to scroll view, do magic for you(scroll state restored) if you are using Fragment

  2. For Activity

    // save index and top position int index = mList.getFirstVisiblePosition(); View v = mList.getChildAt(0); int top = (v == null) ? 0 : (v.getTop() - mList.getPaddingTop());

// ...

// restore index and position mList.setSelectionFromTop(index, top);

SAURABH_12
  • 2,093
  • 1
  • 17
  • 19