E
E
EnerG2013-12-25 02:13:28
Android
EnerG, 2013-12-25 02:13:28

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);

and it is displayed when the application is opened, and closes after the download is complete
public void onPageFinished(WebView view, String url) {
progressDialog.dismiss();}

I open the application, the dialog is displayed, against its background you can see the page
loading after the download is completed, the application crashes, here is the log
j_VoHLrBOmg.jpg
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();
               }  
    });

ps: I hope I explained clearly.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
Toseter, 2013-12-25
@EnerG

Well, progressDialog == null .

ProgressDialog.show(MainActivity.this, "", "Загрузка. Пожалуйста подождите...", true);
returns ProgressDialog.
Should be something like this
progressDialog = ProgressDialog.show(MainActivity.this, "", "Загрузка. Пожалуйста подождите...", true);

G
gadzhi15, 2015-05-06
@gadzhi15

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();
        }
    }
}

Can you please tell me how to properly exit the progressDialog when the page is loaded?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question