1

webview でのダイアログの読み込みに問題があります。私のダイアログはdismisでしたが、完全なwebviewを表示するためにもう一度数秒待つ必要があります..ダイアログの読み込みがdismis webviewであった場合、私が望むのは..これはwebviewの私のコードです:

progressBar = new ProgressDialog(this);
webView = (WebView) findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);

final AlertDialog alertDialog = new AlertDialog.Builder(this).create();
progressBar = ProgressDialog.show(WebViewFacebook.this, "Loading", "Please wait for a moment...");

webView.setWebViewClient(new WebViewClient() {
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        view.loadUrl(url);
        return true;
    }

    public void onPageFinished(WebView view, String url) {
        if (progressBar.isShowing()) {
            progressBar.dismiss(); //--> this progressbar always dismis although mw webview not done ><
        }
    }

    public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
        alertDialog.setTitle("Error");
        alertDialog.setMessage(description);
        alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                //return;
                finish();
            }
        });
        alertDialog.show();
    }
});
webView.loadUrl(strurl);
4

1 に答える 1

1

以下のコードを参照してください

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    view = (WebView) findViewById(R.id.WebView01);
    view.setBackgroundColor(0);  // set the background transparent 

    progressDialog = ProgressDialog.show(view.getContext(), "Loading...", "Loading...");
    progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER    );

    view.setWebChromeClient(new MyWebChromeClient());
    view.getSettings().setJavaScriptEnabled(true);
    view.setWebViewClient(new MyWebViewClient());
    view.loadUrl("http://www.XXX.XXX");

}

そして、クラスを作成します

 private class MyWebViewClient extends WebViewClient {
    @Override
     public boolean shouldOverrideUrlLoading(WebView view, String url) 
    {
        view.loadUrl(url);
        return true;
    }
}


private class MyWebChromeClient extends WebChromeClient {

    @Override
    public void onProgressChanged(WebView view, int newProgress) {
        if(progressDialog!=null){
            if ( newProgress >=80 ) {
                progressDialog.dismiss();
            } else {
                progressDialog.setMessage(newProgress + " % loaded");
            }
        }
        super.onProgressChanged(view, newProgress);
    }
}
于 2012-07-19T11:27:05.563 に答える