我想要一个进度对话框说“请稍候”,而我的代码下载和分析一个XML文件,但进度对话框不会,它会卡住。 我使用的是AsyncTask,xml文件的下载和解析在后台线程中完成,如果我删除进度对话框,代码工作,但在这种情况下,您必须等待约4秒钟才能点击我的动态创建UI的按钮。进度对话框没有被解雇
private class ParseXML extends AsyncTask<Integer, Integer, Document>{
private Context context;
private Activity activity;
private ProgressDialog pd;
public ParseXML(Activity activity) {
this.activity = activity;
context = activity;
pd = new ProgressDialog(context);
}
public void onPreExecute(){
super.onPreExecute();
/* ProgressDialog pd=ProgressDialog.show(XML_PARSER.this,"","Please Wait");*/
}
@Override
protected Document doInBackground(Integer... params) {
DocumentBuilderFactory dbf= DocumentBuilderFactory.newInstance();
Document dom1=null;
try {
//InputStream is=getResources().openRawResource(R.raw.options);
URL requestURL = new URL("my url");
URLConnection connection = requestURL.openConnection();
is = connection.getInputStream();
DocumentBuilder db = dbf.newDocumentBuilder();
dom1=db.parse(is);
Log.i(TAG,"parsing done");
}
catch(ParserConfigurationException pce){
pce.printStackTrace();
}
catch(SAXException se){
se.printStackTrace();
}
catch(IOException ioe){
ioe.printStackTrace();
}
ParseDocument(dom1);
return null;
}
@Override
public void onPostExecute(Document d){
if(pd!=null && pd.isShowing()){
pd.dismiss();
}
super.onPostExecute(d);
}
}
什么你的问题的一些变化?你想要什么?你想关闭进度对话框吗? – 2012-08-08 11:06:06
@ nick-得到了我的解决方案。顺便说一句,我需要关闭我的postExecute()进度对话框。现在它正在工作。 – 2012-08-08 11:33:31