I am working on a webView in an app, where content which webview load changes when a button is pressed (two buttons next and previous , they just change the content in webview).
If I scroll down to a point in webview and press next or previous button it starts from the same point. I just want that everytime the new data is loaded to webview it display the content from the top. I have used:
webView.scrollTo(0, 0);
But doesnt work.How can it work ?Please help anyone?
You can use a webviewclient and set the onPageFinished to scroll to the top: How to listen for a WebView finishing loading a URL?
mWebView.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
view.scrollTo(0,0);
}
});
That way, the content will be loaded when you scroll. It may feel a bit sluggish, but it should work every time.
Maybe delaying it would work? as the content doesn't usualy load instantly
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
webView.scrollTo(0,0);
}
}, 500);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With