Я использую процесс распаковки, для которого я хочу рассчитать его прогресс, вот код со счетчиком:
float counter;
@Override
protected Boolean doInBackground(String... params) {
try {
String zipFile = Path + FileName;
String unzipLocation = Path;
FileInputStream fin = new FileInputStream(zipFile);
ZipInputStream zin = new ZipInputStream(fin);
ZipEntry ze = null;
while ((ze = zin.getNextEntry()) != null) {
counter++;
if (ze.isDirectory()) {
dirChecker(ze.getName());
} else {
FileOutputStream fout = new FileOutputStream(Path
+ ze.getName());
while ((length = zin.read(buffer)) > 0) {
fout.write(buffer, 0, length);
}
publishProgress((int)((counter/747.0)*100));
zin.closeEntry();
fout.close();
}
}
zin.close();
} catch (Exception e) {
mProgressDialog.dismiss();
return false;
}
return true;
}
@Override
protected void onProgressUpdate(Integer... values) {
mProgressDialog.setProgress(values[0]);
}
У меня есть только 1 ZIP-файл, который содержит ровно 747 файлов ... поэтому я использую число 747.
Проблема в том, что значения [0] всегда равны 0 .. Я правильно вычисляю процесс? Как мне это сделать? Спасибо.