【发布时间】:2013-03-30 22:41:54
【问题描述】:
我想在一个进度条中下载多个文件(暂时 2 个)(不重置进度条)
为了做到这一点,我检索了所有文件的总长度,以便在发布进度方法中使用它
问题是我的进度条在达到 50% 后重置为 0,然后再次递增直到另一个 50%
这是我的代码
@Override
protected Void doInBackground(Void... params) {
int totalSizeFile;
totalSizeFile=cm.getLength(url[0]);
totalSizeFile+=cm.getLength(url[1]);
progressBar.setMax(totalSizeFile);
cm.downloadMp3(url[0], "test.mp3", totalTailleFic);
cm.downloadMp3(url[1], "test2.mp3", totalTailleFic);
return null;
}
@Override
protected void onProgressUpdate(Integer... progress) {
textview.setText(String.valueOf(progress[0])+"%");
progressBar.incrementProgressBy(progress[0]);
}
我调用 publishprogress 方法的下载函数的代码
byte[] buffer = new byte[1024];
int bufferLength = 0;
int total=0;
while ((bufferLength = inputStream.read(buffer)) != -1) {
total += bufferLength;
fileOutput.write(buffer, 0, bufferLength);
asynch.publishProgress(bufferLength);
}
非常感谢
【问题讨论】:
标签: android android-asynctask progress-bar