Webview必须自动刷新网站(Webview had to refresh a Website automaticly)

编程入门 行业动态 更新时间:2024-10-25 20:25:41
Webview必须自动刷新网站(Webview had to refresh a Website automaticly)

我是Android Studio的初学者,但我努力刷新网站,但没有任何效果。 可能有一个简单的代码来解决我的问题吗? 请帮忙 !

公共类Motordrehzahl_App扩展活动{

private WebView myWebView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_motordrehzahl__app); myWebView=(WebView) findViewById(R.id.activity_main_webview); WebSettings webSettings = myWebView.getSettings(); webSettings.setJavaScriptEnabled(true); myWebView.loadUrl("http://www.google.com"); refresh();

public void refresh() { while(true) { myWebView.clearView(); myWebView.loadUrl("http://www.google.com"); } }

I am a beginner in Android Studio but I tried very hard to refresh the website but nothing worked. Is there maybe a simple code to solve my problem? please help !

public class Motordrehzahl_App extends Activity {

private WebView myWebView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_motordrehzahl__app); myWebView=(WebView) findViewById(R.id.activity_main_webview); WebSettings webSettings = myWebView.getSettings(); webSettings.setJavaScriptEnabled(true); myWebView.loadUrl("http://www.google.com"); refresh();

public void refresh() { while(true) { myWebView.clearView(); myWebView.loadUrl("http://www.google.com"); } }

最满意答案

您可以使用方法relaod()。 它应该做的工作

final WebView webView = (WebView)findViewById(R.id.webview); WebSettings webSettings = webView.getSettings(); webSettings.setJavaScriptEnabled(true); webView.loadUrl("http://stackoverflow.com/questions"); Button button = (Button) findViewById(R.id.button); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { webView.reload(); } });

我希望它有所帮助。

You can use the method relaod(). It should do the job

final WebView webView = (WebView)findViewById(R.id.webview); WebSettings webSettings = webView.getSettings(); webSettings.setJavaScriptEnabled(true); webView.loadUrl("http://stackoverflow.com/questions"); Button button = (Button) findViewById(R.id.button); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { webView.reload(); } });

I hope it helps.

更多推荐

本文发布于:2023-07-26 02:44:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1269946.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:网站   Webview   refresh   automaticly   Website

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!