如何在AsyncTask android的onPreExecute()上显示进度对话框,下面是我的代码 这里的onPreExecute()方法进度对话框没有显示在UI线程
上//调用AsyncTask
try {
new XYZ().execute(employeeId, password).get();
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (ExecutionException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
class XYZ extends AsyncTask<String, Integer, Void> {
ProgressDialog simpleWaitDialog;
@Override
protected void onPreExecute() {
simpleWaitDialog = new ProgressDialog(TreeViewListDemo.this);
System.out.println("fgfdgfgfgf"+simpleWaitDialog);
simpleWaitDialog.setMessage("Loading...");
simpleWaitDialog.setIndeterminate(true);
simpleWaitDialog.setCancelable(true);
simpleWaitDialog.show();
}
@SuppressWarnings("unchecked")
@Override
protected Void doInBackground(String... params) {
String username = params[0];
String password = params[1];
// this is code for perfoming SOAP web services which is working fine and getting data from server side
return null;
}
}
答案 0 :(得分:3)
您正在调用get()
,可能来自UI线程。从文档中,get()
方法:
如果需要等待计算完成,然后检索 结果。
这意味着您阻止UI线程,使其无法显示进度对话框。我想您要将get()
的调用替换为execute()
答案 1 :(得分:0)
Progres对话框显示 doInBackground
方法已执行。
在这里,您只需在两行以下运行
String username = params[0];
String password = params[1];
几乎没有时间以毫秒为单位,因此您的进度显示并以毫秒为单位关闭。
请将日志值放在onPreExecute()
中以检查您的进度对话框显示我们的不是。
AsyncTask is normally used to perform Network operations..!!
HapPy coading .. !!