嗨,我是 android 新手,如何asynctask
在片段中添加类,new ProgressTask().execute();
我想在屏幕上添加进度条时出错。
这是我的代码
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_zudioz, container, false);
setHasOptionsMenu(true);
webView = (WebView)rootView.findViewById(R.id.webView1);
bar = (ProgressBar) rootView.findViewById(R.id.progressBar);
new ProgressTask().execute();
private class ProgressTask extends AsyncTask <Void,Void,Void>{
@Override
protected void onPreExecute(){
bar.setVisibility(View.VISIBLE);
}
@Override
protected Void doInBackground(Void... arg0) {
//my stuff is here
}
@Override
protected void onPostExecute(Void result) {
bar.setVisibility(View.GONE);
}
}
webView.loadUrl("http://www.zudioz.com");
webView.getSettings().setSupportZoom(true);
webView.getSettings().setBuiltInZoomControls(true);
webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
webView.setScrollbarFadingEnabled(true);
webView.getSettings().setLoadsImagesAutomatically(true);
webView.getSettings().setDomStorageEnabled(true);
webView.setWebViewClient(new WebViewClient());
webView.getSettings().setAllowFileAccess(true);
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setAppCacheEnabled(true);
webView.getSettings().setAppCacheMaxSize(1024*1024*8);
return rootView;
}