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.
更多推荐
发布评论