我需要帮助,我的DIALOG_DOWNLOAD_PROGRESS总是在onPreExecute()上显示100%(第二次下载尝试)。如何从第二次尝试下载的0%开始。需要帮助。感谢
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case DIALOG_DOWNLOAD_PROGRESS:
mProgressDialog = new ProgressDialog(this);
mProgressDialog.setMessage("Downloading file..");
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
mProgressDialog.setCancelable(true);
mProgressDialog.show();
return mProgressDialog;
default:
return null;
}
}
类DownloadFileAsync扩展了AsyncTask {
@Override
protected void onPreExecute() {
super.onPreExecute();
showDialog(DIALOG_DOWNLOAD_PROGRESS);
}
...
}
protected void onProgressUpdate(String... progress) {
Log.d("ANDRO_ASYNC",progress[0]);
mProgressDialog.setProgress(Integer.parseInt(progress[0]));
}
@Override
protected void onPostExecute(String unused) {
dismissDialog(DIALOG_DOWNLOAD_PROGRESS);
}
答案 0 :(得分:0)
因为onCreateDialog
只被调用一次来创建对话框,所以你必须重置onPrepareDialog
中的对话框,每次在显示对话框之前调用该对话框。
@Override
protected void onPrepareDialog(int id, Dialog dialog, Bundle args)
if (id == DIALOG_DOWNLOAD_PROGRESS)
mProgressDialog.setProgress(0);
}
答案 1 :(得分:0)
protected Dialog onCreateDialog(int id){
switch(id){
case 0:
_progressDialog = new ProgressDialog(null);
_progressDialog.setTitle("Downloading files..");
_progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
_progressDialog.setButton(DialogInterface.BUTTON_POSITIVE, "Hide", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Log.d(TAG, "hide");
}
});
_progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Log.d(TAG, "cancel");
cancelLoad();
}
private void cancelLoad() {
// TODO Auto-generated method stub
}
});
}
return _progressDialog;
}