user3213206
user3213206

Reputation: 45

Android WebView Progress Dialog not end

I have a WebView with a ProgressDialog so my Problem is that the ProgressDialog not end after the Website is loaded. The ProgressDialog will not dismiss. I use this Code

public class MainActivity extends Activity {
private WebView webView;
ProgressDialog mProgress;

@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    webView = (WebView) findViewById(R.id.webView1);
    webView.getSettings().setJavaScriptEnabled(true);
    mProgress = ProgressDialog.show(this, "Loading", "Bitte warten...");
    mProgress.setMax(100);
    webView.setWebViewClient(new WebViewClient() {
         });
         webView.setWebViewClient(new WebViewClient() {
           public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
             Toast.makeText(MainActivity.this, "Oh no! " + description, Toast.LENGTH_SHORT).show();
           }
         });

         webView.loadUrl("http://google.de/");
}
public class myWebClient extends WebViewClient
{
    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) {
        // TODO Auto-generated method stub
        super.onPageStarted(view, url, favicon);
    }

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        // TODO Auto-generated method stub
        view.loadUrl(url);
        return true;

    }

    @Override
    public void onPageFinished(WebView view, String url) {
        // TODO Auto-generated method stub
         if(mProgress.isShowing()) {
             mProgress.hide();
         }
    }
}

Hope anybody can help me to solve this Problem

Upvotes: 0

Views: 352

Answers (2)

felli mohamed hedi
felli mohamed hedi

Reputation: 309

Delete this line:

webView.setWebViewClient(new WebViewClient() { });

and replace

webView.setWebViewClient(new WebViewClient() { 
  public void onReceivedError(WebView view, int errorCode, String                             description, String failingUrl) {
    Toast.makeText(MainActivity.this, "Oh no! " + description, Toast.LENGTH_SHORT).show();
  }
});

with

webView.setWebViewClient(new myWebClient (){
  public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
    Toast.makeText(MainActivity.this, "Oh no! " + description, Toast.LENGTH_SHORT).show();
  }
});

Upvotes: 1

ρяσѕρєя K
ρяσѕρєя K

Reputation: 132972

Use myWebClient class object where overriding onPageFinished method for setting WebViewClient :

webView.setWebViewClient(new myWebClient());

and also remove second call of webView.setWebViewClient.

Upvotes: 0

Related Questions