12

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?

1

3 Answers 3

14

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.

Sign up to request clarification or add additional context in comments.

Comments

9

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); 

Comments

4

Use thread and delay the scrollTo to make it work

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.