Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Right this is the quick answer, you should really implement your own class for the WebViewClient, you should show the dialog in that class as well but you'll figure that out. </p> <p>First, make your dialog global, (in your real app you might want to pass it in to your client, or declare it in the webviewclient, then override on onPageStarted as well).</p> <pre><code> ProgressDialog dialog; </code></pre> <p>then simply:</p> <pre><code> webview.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); dialog.dismiss(); } }); public void onClick(View v){ switch(v.getId()){ case R.id.refresh: dialog = ProgressDialog.show(Quotes.this, "", "Loading...", true); webview.reload(); } } } </code></pre> <p>This is the API you need: <a href="http://developer.android.com/reference/android/webkit/WebViewClient.html">WebViewClient</a></p> <p><em>EDIT</em></p> <p>Ok it was annoying me, here is the proper way:</p> <pre><code> public class Quotes extends Activity implements OnClickListener{ private WebView webview; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); webview = (WebView) findViewById(R.id.scroll); webview.getSettings().setJavaScriptEnabled(true); webview.setWebViewClient(new MyWebViewClient(this)); webview.loadUrl("http://www.dgdevelco.com/quotes/quotesandroid.html"); findViewById(R.id.refresh).setOnClickListener(this); } public void onClick(View v){ switch(v.getId()){ case R.id.refresh: webview.reload(); break; } } } </code></pre> <p>The new class:</p> <pre><code> public class MyWebViewClient extends WebViewClient { private Context mContext; private ProgressDialog mDialog; public MyWebViewClient(Context context){ mContext = context; } @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { super.onPageStarted(view, url, favicon); mDialog = ProgressDialog.show(mContext, "", "Loading...", true); } @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); mDialog.dismiss(); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload