-2

I have an Activity with a scroll view and 2 buttons, When open this activity both buttons are disabled. What I want is, when I reach the end of the scroll view, enable both buttons to user to accept or decline the content. How can I do this in simple way.

Button before enabled

image

Thanks in advance.

Waseem
  • 183
  • 14

1 Answers1

2

I have done this things with webView here is my code, hope it will help you.

webView.setOnScrollChangedCallback(new ObservableWebView.OnScrollChangedCallback() {
                @Override
                public void onScroll(int l, int t) {
                    int tek = (int) Math.floor(webView.getContentHeight() * webView.getScale());

                    if (tek - webView.getScrollY() <= webView.getHeight() + 5) {
                        // enable your button 
                    }

                }
            });

this is the class

public class ObservableWebView extends WebView
{
    private OnScrollChangedCallback mOnScrollChangedCallback;
public ObservableWebView(final Context context)
{
    super(context);
}

public ObservableWebView(final Context context, final AttributeSet attrs)
{
    super(context, attrs);
}

public ObservableWebView(final Context context, final AttributeSet attrs, final int defStyle)
{
    super(context, attrs, defStyle);
}

@Override
protected void onScrollChanged(final int l, final int t, final int oldl, final int oldt)
{
    super.onScrollChanged(l, t, oldl, oldt);
    if(mOnScrollChangedCallback != null) mOnScrollChangedCallback.onScroll(l, t);
}

public OnScrollChangedCallback getOnScrollChangedCallback()
{
    return mOnScrollChangedCallback;
}

public void setOnScrollChangedCallback(final OnScrollChangedCallback onScrollChangedCallback)
{
    mOnScrollChangedCallback = onScrollChangedCallback;
}

/**
 * Impliment in the activity/fragment/view that you want to listen to the webview
 */
public static interface OnScrollChangedCallback
{
    public void onScroll(int l, int t);
}

}

happy coding.

Amit Verma
  • 341
  • 2
  • 17