2011-09-09 34 views
1

我使用,我想计算它的进展一个解压缩过程中的进步,这里是与计数器代码:这恰好包含747Java的计算上解压缩过程

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.
问题是值[0]始终为0 ..我是在计算过程的权利?我应该怎么做?谢谢。

回答

1

使用从进度上一次发布的值:

mProgressDialog.setProgress(values[values.length - 1]); 

可能出现的问题:

  • 这可能是解压的进步是如此之快(或GUI更新很慢),其values = [0, 1, .... 99]
  • 您的进度对话框设置不正确(setMaxsetMin