Document doc = new Obtainer(context, uri).execute().get();
活动类中的此代码呈现了从网址获取xml文档的Obtainer(它扩展了AsyncTask)。这是onPreExecute方法:ProgressDialog未显示在AsyncTask中
protected void onPreExecute() {
super.onPreExecute();
System.out.println("Pre execute began");
exception = null;
dialog = new ProgressDialog(context);
dialog.setMessage("Loading started");
dialog.setIndeterminate(true);
dialog.setCancelable(false);
System.out.println("Preexecute end");
dialog.show();
}
上下文在构造函数中设置:
public Obtainer(Context c, String addr) {
context = c;
address = addr;
}
在运行时,我可以在控制台输出中看到这两个“预执行所开始”和“Preexecute结束”,但进度对话框不显示。问题是什么?
您的代码看起来很好,只知道什么是书籍DOC上下文=新获取器(背景下,URI).execute()得到();?。尝试将 .this而不是上下文... –
user370305
2011-12-24 09:25:04