我想顯示一個preloader,然後加載完整的頁面作爲webview但這裏是一個小問題,我已經做了preloader但它繼續下去,並沒有結束它。onPreExcute作爲預加載器的webview中的片段
如何告訴腳本在加載頁面時停止顯示對話框。
public class EzFragment extends Fragment {
public ProgressDialog pDialog;
public EzFragment(){}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
new getFeed().execute();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_ez, container, false);
WebView myWebView = (WebView) rootView.findViewById(R.id.webView1);
String summary = "<html><head> <link rel=\"stylesheet\" type=\"text/css\"
href=\"http://www.example.com/demo/android_connect/assets/style/jquery.fullPage.css\" /></head></html>";
myWebView.loadData(summary, "text/html", null);
myWebView.loadUrl("http://www.example.com/demo/android_connect/get_ez_webmob.php");
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
return rootView;
}
private class getFeed extends AsyncTask<Void, Void, Document> {
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(getActivity());
pDialog.setTitle("Connect to Server");
pDialog.setMessage("This process can take a few seconds to a few minutes, depending on your Internet Connection Speed.");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
@Override
protected Document doInBackground(Void... arg0) {
// TODO Auto-generated method stub
return null;
}
}
是否有可能的WebView添加到文檔doInBackground才能在後臺加載頁面?!
謝謝,但我應該在哪裏添加此代碼?!在我的課結束之前?! –
@MacTaylor:'webSettings.setJavaScriptEnabled(true); 'line –
謝謝,這個方法有一個小問題,當頁面加載開始的時候,preloader就消失了!你認爲添加webview doInBackground不是一個更好的舉措? –