Webview with asynctask on Android

后端 未结 1 1399
礼貌的吻别
礼貌的吻别 2020-11-30 13:24

i want to do it which the progress dialog waits the loading item on webview. How can i do it which dialog.dismiss() event depend on loading ite

相关标签:
1条回答
  • 2020-11-30 14:04

    Don't use AsyncTask, as you are not in charge of loading the webview. If you want to show a progress dialog, here is how to do it.

    private ProgressDialog dialog = new ProgressDialog(WebActivity.this);
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.webview);
        webView = (WebView) findViewById(R.id.webView1);
    
        Bundle extras = getIntent().getExtras();
        String url=extras.getString("adres");
    
        webView.setWebViewClient(new WebViewClient() {
            @Override
            public void onPageFinished(WebView view, String url) {                  
                if (dialog.isShowing()) {
                    dialog.dismiss();
                }
            }
        });
        dialog.setMessage("Loading..Please wait.");
        dialog.setCanceledOnTouchOutside(false);
        dialog.show();
        webView.loadUrl(url);
    
    
    
        WebSettings webSettings = webView.getSettings();
        webSettings.setJavaScriptEnabled(true);
    }
    

    The idea is that you show the dialog, you start loading the url, and when the webclient sees that the page has finished loading, it dismisses the dialog.

    0 讨论(0)
提交回复
热议问题