views:

27

answers:

1

Hi, I update the html in a webView using loadData() followed by a reload(). I get the new data to display but the scroll of the page has not updated. I want to keep the view of the page at the bottom. I can wait a long time and it still doesn't update. Once I click the webView the scroll bars adjust and I can drag to the bottom of the page and see the new text.

Things I have tried: - multiple settings and calls in onPageFinished(). None worked because the getContentHeight() hasn't changed yet. I have also tried to scrollTo(100 + getContentHeight) and that doesn't work. - pageDown(true)

  • calling requestLayout() after reload()

  • browser.requestFocusFromTouch() - still no good, thinking i could simulate my click.

  • adding a few br tags. This worked a bit, but the number of br's has to equal the number of lines of new text. Since the number of new lines is not something that can be exactly determined based on orientation and screen variables it's not a good fix. Any ideas? TIA

+1  A: 

If you want the webview to be scrolled to the bottom after it's finished loading, I found I had to use pageDown(true) in onNewPicture. (I believe that's the event fired when a view is finished drawing.)

So the code looks something like

   webView.setPictureListener( new WebView.PictureListener() {

        public void onNewPicture(WebView view, Picture picture) {
            webView.pageDown(true);
        }
    }

Using pageDown has the unfortunate problem of visibly scrolling the page; I'm having problems finding any other way to jump to the bottom of the webView, found this question while looking for a solution! (I haven't tried reaching inside the WebView and using javascript yet, though.)

starwed
I must have another glitch. I see the page flicker during pageDown (Yeh! Never got that before), yet it is going to the original end of page. The contentHeight isn't getting updated so it is going to a faux end of page. Sheeesh!
Jim
I am marking this as answered since pageDown(true) is triggering for me. I asked another question on how to get contentHeight to recalculate.
Jim