My answer is based on a little research so I am not sure about the exact code but I will suggest an approach here
First you can have a Fragment
or Activity
with the WebView
view type in the layout file respectively and depending on your use case, get the reference for the WebView
. We will pass your list of urls to the activity containing the Webview
Say, we do it like so
val arrayList = getIntent().getArrayListExtra("urls")
val webView = findViewById<WebView>(R.id.myWebview)
Now we can listen to scroll changes of the WebView
and wait for the user to reach the end of the WebView
page as given in the following link
How to check the scrollend of WebView
And then when the scroll end is reached, we can load the next url from the array
webView.setOnScrollChangeListener((view, i, i1, i2, i3) -> {
int r1 = webView.computeVerticalScrollRange();
int r2 = webView.computeVerticalScrollExtent();
if (i1 == (r1 - r2)) {
webView.loadUrl(arrayList.get(1) // Or Whatever your next
index is
// Maybe maintain a global variable for which url is currently
loaded
}
});
To make the experience nice for the user you can consider setting a WebViewClient
for your WebView
and override onProgressChanged
to show the progress to the user, just in case he doesn't feel lost