解压缩时进度条

时间:2016-01-14 06:31:15

标签: java android

在我的应用程序中,它需要解压缩一个压缩文件夹。在我的代码中,它无法使用它添加进度条。所以我用Google搜索并在stackoverflow Progress Bar with unzipping of file中找到了一个已回答的问题。

(复制)

private class Decompress extends AsyncTask<Void, Integer, Integer> {

   private String _zipFile;   
   private String _location;
   private int per = 0;

    public Decompress(String zipFile, String location) {
            _zipFile = zipFile;     
            _location = location;      
            _dirChecker("");   
            }    

     protected Integer doInBackground() {
         try  {       
            ZipFile zip = new ZipFile(_zipFile);
            bar.setMax(zip.size());
            FileInputStream fin = new FileInputStream(_zipFile);       
            ZipInputStream zin = new ZipInputStream(fin);
            ZipEntry ze = null;       
            while ((ze = zin.getNextEntry()) != null) {

                Log.v("Decompress", "Unzipping " + ze.getName());          
                if(ze.isDirectory()) {           
                    _dirChecker(ze.getName());         
                    } else {      
                // Here I am doing the update of my progress bar

                        per++;
                        publishProgress(per);

                        FileOutputStream fout = new FileOutputStream(_location +ze.getName());           
                        for (int c = zin.read(); c != -1; c = zin.read()) {  

                            fout.write(c);           
                            }            
                        zin.closeEntry();          
                        fout.close();         
                        }                
                }       
            zin.close();    
            } catch(Exception e) {       
                Log.e("Decompress", "unzip", e);    
                }    
        }    


         }
         return totalSize;
     }

     protected void onProgressUpdate(Integer... progress) {
         bar.setProgress(per); //Since it's an inner class, Bar should be able to be called directly
     }

     protected void onPostExecute(Integer... result) {
         Log.i("Completed. Total size: "+result);
     }
    }

当我试图执行它时会出现错误错误:(152,9)错误

FileexplorerActivity.Decompress is not abstract and does not override abstract method doInBackground(Void...) in AsyncTask

我该如何解决这个问题。

2 个答案:

答案 0 :(得分:0)

Asynctask

中没有没有参数的doBackground()
protected abstract Result doInBackground (Params... params)

您应该在doBackground()中包含参数。

答案 1 :(得分:0)

doInBackground()中加入参数:

protected Integer doInBackground(Void... voids)
{
    ....
    return totalSize;
}
相关问题