Answer the question
In order to leave comments, you need to log in
WebView calling ProgressDialog and closing when page is finished loading?
In general, I need to display a loading indicator when opening the page, for this I created a progress dialog
ProgressDialog.show(MainActivity.this, "", "Загрузка. Пожалуйста подождите...", true);
public void onPageFinished(WebView view, String url) {
progressDialog.dismiss();}
package com.application;
[Импорты]
private WebView webView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = (WebView) findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("http://site.ru/");
ProgressDialog.show(MainActivity.this, "",
"Загрузка. Пожалуйста подождите...", true);
// Страница ошибки
webView.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
progressDialog.dismiss();
}
});
Answer the question
In order to leave comments, you need to log in
Well, progressDialog == null .
ProgressDialog.show(MainActivity.this, "", "Загрузка. Пожалуйста подождите...", true);
returns ProgressDialog. progressDialog = ProgressDialog.show(MainActivity.this, "", "Загрузка. Пожалуйста подождите...", true);
public class MainActivity extends Activity {
private WebView mWeb;
private class WebViewer extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading (WebView view, String url)
{
view.loadUrl(url);
return true;
}
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mWeb=(WebView)findViewById(R.id.web);
mWeb.getSettings().setJavaScriptEnabled(true);
mWeb.loadUrl("http://randevu05.ru/");
mWeb.setWebViewClient(new WebViewer());
ProgressDialog.show(MainActivity.this, "", "Загрузка. Пожалуйста подождите...", true);
}
@Override
public void onBackPressed() {
if (mWeb.canGoBack()) {
mWeb.goBack();}
else {
super.onBackPressed();
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question