如何在Android中恢复活动时显示进度条?

时间:2018-03-27 05:22:58

标签: progress-bar android-adapter

我的进度条有问题。我有适配器,因为我有每个孩子的下载按钮,当我按下载按钮我正在显示进度栏中的进度。它的工作完美到这里。但现在,当回去(进展14%,它在asynctack(意思是在中间我回来然后那个))并再次来到那个适配器,剩下的(意味着任何%progess)需要显示..如何这样做?

 @Override
protected Void doInBackground(Void... params) {
    final int TIMEOUT_CONNECTION = 5000;//5sec
    final int TIMEOUT_SOCKET = 30000;//30sec
    long bytes = 1024 * 1024;
    try{
        URL url = new URL(downloadFromPath);
        //Open a connection to that URL.
        URLConnection ucon = url.openConnection();
        ucon.connect();
        int   fileLength = ucon.getContentLength();
        ucon.setReadTimeout(TIMEOUT_CONNECTION);
        ucon.setConnectTimeout(TIMEOUT_SOCKET);

        InputStream is = ucon.getInputStream();
        BufferedInputStream inStream = new BufferedInputStream(is, 1024 * 5);
        //Internal storage
        String filePath = DestPath+"/"+mId+".zip";
        FileOutputStream outStream = new FileOutputStream(filePath);
        byte[] buff = new byte[5 * 1024];
        //Read bytes (and store them) until there is nothing more to read(-1)
        int len;
        long total = 0;
        while ((len = inStream.read(buff)) != -1)
        {
            total += len;
            publishProgress((int)((total*100)/fileLength));
            outStream.write(buff,0,len);

        }

        //clean up
        outStream.flush();
        outStream.close();
        inStream.close();
        downloadSuccess = true;


        try {

            if(downloadSuccess)
             unzipDownloadfileNew(filePath,DestPath);

        } catch (Exception e) {
            e.printStackTrace();
        }

    }
    catch (IOException e){
        downloadSuccess = false;
        downloadCallBackListener.updateProgressForDownload(false);
    }
    return null;
}
enter code here
protected void onProgressUpdate(Integer... values) {
    super.onProgressUpdate(values);



    if (getCircular_Progress()!=null){
       // if (getCircular_Progress().getTag().equals(mId)) {
            getCircular_Progress().setVisibility(View.VISIBLE);
            getCircular_Progress().setProgress(values[0]);
            getCircular_Progress().invalidate();

        //}
    }
    if (downloadText!=null){
         if (downloadText.getTag().equals(mId)) {
        downloadText.setVisibility(View.VISIBLE);
        downloadText.setText(String.valueOf(values[0]));
        downloadText.invalidate();

        }
    }

   /* if(circular_Progress!=null)
    circular_Progress.setVisibility(View.VISIBLE);
    circular_Progress.setProgress(values[0]);*/

}

0 个答案:

没有答案