Android WebView - 第一个 LoadData() 工作正常,后续调用不会更新显示
第一次调用 LoadData() 后, onLoadResource 事件按其应有的方式触发,并且显示正常。接下来,我想用新页面刷新屏幕,当我第二次使用 LoadData() 时,页面不会更新,并且 onLoadResource() 不会触发。
然后第二次调用 LoadData() 只会触发 onPageFinished ... onPageStarted 永远不会触发!
解决方法是在 LoadData() 之后调用 .reload() ,但这会在活动中的其他逻辑期间导致各种问题。
为什么 LoadData() 不能多次工作?
我使用的是非常简单的 HTML,并且由于使用 .reload() 使其工作,所以我的 LoadData() 语句似乎不是问题。
任何想法都会有帮助,TIA
After the 1st call to LoadData() the event onLoadResource fires as it should and the display is fine. Next I want to refresh the screen with a new page, when I use LoadData() the second time the page does not update and onLoadResource() DOES NOT FIRE.
Then second call to LoadData() onlyfires onPageFinished ... onPageStarted never fires!
A work around was to call .reload() after LoadData() but that causes all sorts of problems during the other logic in the activity.
Why doesn't LoadData() work multiple times?
I am using extremely simple HTML, and since using .reload() makes it work my LoadData() statement doesn't seem to be the problem.
Any Ideas would be helpful, TIA
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
使用
它效果很好。
loaddata
下次加载数据时不会刷新。Use
it works fine.
loaddata
does not refresh next time the data is loaded.由于某种原因,您必须先清除内容。 “load...”方法似乎没有明确附加其内容,但它不起作用。我认为它曾经是
WebView.clearView()
但已被弃用。 Android site 上已弃用方法的文档实际上告诉您使用 WebView.loadUrl("about:blank") 来替代该方法。所以......对我有用。看起来有点肮脏,但我不敢违背谷歌!我不确定是否有其他人在这样做,但我只是加载一个我从“资产”中读取的字符串。我用它来显示帮助文档。所以我没有使用任何实际的 URL;我只是使用 WebView 作为 HTML 渲染器。
注意:对于那些新手(比如大约一个月前的我),请确保将“WebView”替换为变量的实例。这些不是静态方法。
For some reason you have to clear the content first. The "load..." methods don't seem to be explicitly appending their content but it doesn't work. I think it used to be
WebView.clearView()
but that was deprecated. The doc for the deprecated method on the Android site actually tells you to useWebView.loadUrl("about:blank")
as a replacement for that method. So......does the trick for me. It seems a little dirty but I wouldn't dare disobey Google! I'm not sure if anyone else is doing this but I am just loading a String in that I had read from an "asset." I'm using it to display help docs. So I'm not using any actual URL's; I'm just using the WebView as an HTML renderer.
Note: For those newbies out there (like me only about a month ago) make sure to replace "WebView" with an instance of your variable. These are not static methods.
这样的方法将会奏效
Such approach will work
对于仍然遇到问题的人,我找到了一个快速解决方案,只需使用处理程序即可
Those who are still having the issue i found a quick solution just use a handler for this
您需要在主线程中加载DataWithBaseURL
You need to loadDataWithBaseURL in main thread
我能够通过每次为 html 文档提供不同的 id 来使浏览器在每次更新时刷新:请参阅下面的 // WEBVIEW。
I was able to make the browser refresh on each update by giving the html document a different id each time: please see below at // WEBVIEW.