Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9267525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:34:14+00:00 2026-06-18T14:34:14+00:00

How to implement the Scroll Listener for WebView in Android i tried this but

  • 0

How to implement the Scroll Listener for WebView in Android

i tried this but its not calling my Log.i on scrolling the webview.

package com.example.webview.full.width;
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.webkit.WebView;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;

public class scorllableWebview extends WebView implements OnScrollListener {


Context ctx;
AttributeSet atrs;

public scorllableWebview(Context context) {
    super(context);

    ctx = context;
}

public scorllableWebview(Context context, AttributeSet atters){
    super(context, atters);

    ctx = context;
    atrs = atters;
}

@Override
public void onScroll(AbsListView view, int firstVisibleItem,
        int visibleItemCount, int totalItemCount) {

    Log.i("onScroll", "Called");
}

@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {


    Log.i("onScrollStateChanged", "Called");

}
}

Here is my MainActivity.java

package com.example.webview.full.width;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.view.Menu;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;

public class MainActivity extends Activity {

ProgressDialog progressDialog;
scorllableWebview wv;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    wv = (scorllableWebview) findViewById(R.id.scorllableWebview);

    wv.getSettings().setJavaScriptEnabled(true);

    wv.getSettings().setBuiltInZoomControls(true);
    wv.getSettings().supportZoom();

    progressDialog = ProgressDialog.show(MainActivity.this,
            "Loading Book...!", "Please Wait");
    progressDialog.setCancelable(true);

    String htnlString = "<!DOCTYPE html><html><body style = \"text-align:center\"><script type=\"text/javascript\">for(a=1;a<=10;a++)document.write('<img style=\"border-style:dotted;border-width:10px;border-color:black;\"src=\"http://myURL.com/books_snaps/EN567/'+a+'.jpg\" alt=\"Page Not Found\"/>');</script></body></html>";
    // width=\"100%\"
    wv.setWebViewClient(new WebViewClient() {

        @Override
        public void onPageFinished(WebView view, String url) {
            progressDialog.dismiss();
            Toast.makeText(MainActivity.this, "Completed",
                    Toast.LENGTH_SHORT).show();
            wv.pageUp(true);
            super.onPageFinished(view, url);
        }

    });

    wv.loadDataWithBaseURL(null, htnlString, "text/html", "UTF-8", null);

}
   }

and here is my XML file.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<com.example.webview.full.width.scorllableWebview
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scorllableWebview"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

</RelativeLayout>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T14:34:16+00:00Added an answer on June 18, 2026 at 2:34 pm

    Something like:

    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, oldl, oldt);
        }
    
        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, int oldl, int oldt);
        }
    }
    

    Should work, this is untested but this works for almost every other view in Android.

    You would implement like:

    wv = (ObservableWebView) findViewById(R.id.scorllableWebview);
    wv.setOnScrollChangedCallback(new OnScrollChangedCallback(){
        public void onScroll(int l, int t, int oldl, int oldt){
            if(t> oldt){
                //Do stuff
                System.out.println("Swipe UP");
                //Do stuff
            }
            else if(t< oldt){
                System.out.println("Swipe Down");
            }
            Log.d(TAG,"We Scrolled etc...");
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to implement Paginated list View in android so when I scroll down
I want to implement this simple animation in knockout: function scroll(back) { var scrollContainer
im trying to implement a scroll to top animation on my site http://www.cmclove.org/bootstrap but
I tried to implement an infinite scroll, or a load on scroll if you
I'm trying to implement the following guide to my custom wordpress theme http://tomsbigbox.com/wordpress-load-more-posts-on-page-scroll/ Unfortunately
I am trying to implement a scroll to DIV (i.e. smooth scrolling with some
I'm trying to use Android GalleryView to implement a view that can scroll horizontally
I'm developing 2D Side scroll Android Game, using AndEngine and its BOX2D extension. I
Do you have any idea how to implement an indefinite scroll widget like google
I am supposed to implement a gesture-based menu in which you scroll through a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.