3

进度对话框出现,可能在异步任务完成后延迟,在 doInBackground 中它调用 Web 服务并解析 xml,如果 xml 中的文件更大,则活动必须等待几秒钟

@Override
protected void onPreExecute(){
    super.onPreExecute();
    completed=false;
    this.progressDialog.show();

}

@Override
protected Boolean doInBackground(Integer... params) {
    t=HttpHelper.callWebService( url, soapAction,xml);
    if (t.equals("")){  
        return false;
    }
    else {
        try {
            SAXParserFactory spf = SAXParserFactory.newInstance();
            SAXParser sp = spf.newSAXParser();
            XMLReader xr = sp.getXMLReader();
            XMLHelperFile myXmlHelperFile = new XMLHelperFile();
            xr.setContentHandler(myXmlHelperFile);
            InputSource is = new InputSource(new StringReader(CallWebFile.t)); 
            xr.parse(is);
            mesaj = myXmlHelperFile.getParsedData(); 
            completed=true;
    } catch (Exception e) {
            e.printStackTrace();
        }
        return true;
    }

}

@Override
protected void onPostExecute(Boolean result) {
    super.onPostExecute(result);
    if (completed==true && progressDialog.isShowing()) progressDialog.dismiss();
}


@Override
protected void onProgressUpdate(Integer... values) {
    super.onProgressUpdate(values);


    }
}
4

2 回答 2

1

只是一个猜测。在 preExecute() 中初始化进度对话框

于 2012-11-21T14:42:49.730 回答
0

publishProgress(some int value);您在 doInBackground()中缺少对 publishProgress 的调用

于 2012-11-21T14:44:32.030 回答