【发布时间】:2014-04-28 06:30:33
【问题描述】:
我已经实现了文件的下载并在对话框中显示进度。一切正常。现在在实现这些东西时,我以以下方式实现了对话框代码:
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case progress_bar_type: // we set this to 0
pDialog = new ProgressDialog(this);
pDialog.setMessage("Fetching Attachment. Please wait...");
pDialog.setIndeterminate(false);
pDialog.setMax(100);
pDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
pDialog.setCancelable(false);
pDialog.show();
return pDialog;
default:
return null;
}
}
使用以下代码计算和显示百分比:
publishProgress((int) ((total * 100) / filelength));
我的 AsyncTask 方法:
protected void onPreExecute() {
showDialog(progress_bar_type);
}
protected void onProgressUpdate(Integer... progress) {
pDialog.setProgress(progress[0]);
}
现在我的对话框正在显示下载进度,并且还以 % 和 30/100 (即 X/Y 格式)显示进度更新。
现在我只想显示百分比而不是 X/Y 格式,类似于 android 中的 gmail 下载对话框。
【问题讨论】:
-
添加的代码不显示任何 X/Y 或进度百分比。在此处添加正确的代码...
标签: android android-asynctask progressdialog