【发布时间】:2014-12-18 13:01:47
【问题描述】:
我无法让 ProgressDialog 在 AsyncTask 中运行:
private class Upload extends AsyncTask<String, Void, Void> {
ProgressDialog pd;
protected void onPreExecute() {
super.onPreExecute();
pd = new ProgressDialog(Activity.this);
pd.setMessage("Message");
pd.setIndeterminate(false);
pd.setMax(100);
pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
pd.setCancelable(false);
pd.show();
}
@Override
protected Void doInBackground(String... params) {
.......
public void write(byte[] bts, int st, int end) throws IOException {
totalSent += end;
progress = (int) ((totalSent / (float) contentLength) * 100);
publishProgress("Loaded "+progress+"%");
out.write(bts, st, end);
}
.......
}
protected void onProgressUpdate(String... progress) {
Log.d("ANDRO_ASYNC", progress[0]);
pd.setProgress(Integer.parseInt(progress[0]));
}
protected void onPostExecute(Void result) {
super.onPostExecute(result);
if (pd != null)
{
pd.dismiss();
}
}
进度对话框有效,但没有任何进展。但是在我看到的日志中,这个进度是正确的。 所以,没有进行中的问题。
对于上面的代码,我收到一个错误,说“AsyncTask String,Void,Void 类型中的方法 publishProgress(Void...) 不适用于参数 (String)”。
无论我做什么,它都不起作用。我想,我错过了什么。请帮忙)
【问题讨论】:
标签: android android-asynctask progressdialog