onPreExecute 作为片段中 webview 的预加载器
onPreExecute as preloader for webview in a fragment
我试图在将完整页面加载为 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 添加到 Document doInBackground 以便在后台加载页面?!
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
if (pDialog.isShowing()) {
pDialog.dismiss();
}
}
在执行后停止对话框..
How can I tell the script to stop showing dialog when the page is
loaded .
使用 onPageFinished
关闭 ProgressDialog
因为 onPageFinished
方法在 WebView 中完全加载页面时被调用:
myWebView.setWebViewClient(new WebViewClient(){
//.....
@Override
public void onPageFinished(WebView view, String url) {
Log.d("mytag","Page Loading Finished!");
super.onPageFinished(myWebView, url);
// dismiss ProgressDialog here
}
});
我试图在将完整页面加载为 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 添加到 Document doInBackground 以便在后台加载页面?!
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
if (pDialog.isShowing()) {
pDialog.dismiss();
}
}
在执行后停止对话框..
How can I tell the script to stop showing dialog when the page is loaded .
使用 onPageFinished
关闭 ProgressDialog
因为 onPageFinished
方法在 WebView 中完全加载页面时被调用:
myWebView.setWebViewClient(new WebViewClient(){
//.....
@Override
public void onPageFinished(WebView view, String url) {
Log.d("mytag","Page Loading Finished!");
super.onPageFinished(myWebView, url);
// dismiss ProgressDialog here
}
});