1

现在我试图在 webview 中显示一个页面,加载需要一些时间,同时我想显示一个 progressDialog。我能做的最好的是下面的代码,但问题是我在 onCreateView 中执行此操作,因此 progressDiealog 仅在创建视图之前显示,这不是我想要的。我知道我必须在 onActivityCreated 中使用它,但我不知道该怎么做,提前谢谢大家

public class someFragment extends SherlockFragment {
Context context;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup group, Bundle saved)
    {
    View v = inflater.inflate(R.layout.some_layout, group, false);
    final ProgressDialog pd = ProgressDialog.show(getActivity(),  "", "Loading", true);

    final WebView myWebView = (WebView) v.findViewById(R.id.webViewsome);
    myWebView.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageFinished(WebView view, String url) {
            pd.dismiss();
        }
    });

    myWebView.getSettings().setPluginsEnabled(true);
    myWebView.getSettings().setBuiltInZoomControls(false); 
    myWebView.getSettings().setSupportZoom(false);
    myWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);   
    myWebView.getSettings().setJavaScriptEnabled(true);
    myWebView.getSettings().setAllowFileAccess(true); 
    myWebView.getSettings().setDomStorageEnabled(true);
    myWebView.setInitialScale(25);

    myWebView.getSettings().setDefaultZoom(ZoomDensity.FAR);

    myWebView.loadUrl("http://www.test.com/test-0.jpg");

    return v;
    }
}
4

2 回答 2

1

试试这个SomeFragment

private class MyWebViewClient extends WebViewClient {

    @Override
    public void onPageFinished(WebView view, String url) {
        //remove your progressdialog here
        super.onPageFinished(view, url);
    }

    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) {
        //show your progressdialog here
        super.onPageStarted(view, url, favicon);
    }

}

然后:

webView.setWebViewClient(new MyWebViewClient());
于 2012-08-29T11:56:59.200 回答
0

您可以做的一件事是,以aonCreateView开头。在(网页完全加载后)中,取消该任务。希望它有用。AsyncTaskprogressDialogonPageFinishedwebView

于 2012-08-29T12:58:43.650 回答