在GridView中设置ProgressBar当活动重新进入时设置ProgressValue

时间:2013-09-26 13:06:42

标签: android gridview

亲爱的Stackoverflowians

我有一个Gridview,因为每个项目都有项目按钮单击

上可见的水平进度条设置

我通过使用asyncTask来实现它,但是,现在我的问题是 1)当我在进行中向上或向下滚动时,进度条在关于位置变化的可见其他项目中进展

2)更改活动并再次进入此活动,进度条在该网格项中不可见,但在backgroud中运行的进度我在Logcat中检查它。

这是我的流程enter image description here

的示例

以下是进度下载的代码

private void UpdateDB(String strFilename,int lintIssueId,boolean bPreview,ImageView btnDownload,ImageView btnView)
    {
        try{

            btnDownload.setVisibility(View.GONE);
            btnView.setVisibility(View.VISIBLE);


        }catch(Exception ex){}
    }
    private static class SCSDownload extends AsyncTask<String, Integer, String>
    {
        Main_Page activity;
        MiddlewareInterface AMI=MiddlewareInterface.GetInstance();
        ProgressBar mProgressbar;
        RelativeLayout mRtProgress;
        ImageView btnDownload,btnView;
        int issueid;
        boolean bPrev;
        Context context;
        SCSDownload(Main_Page act,ProgressBar mProgressbar,RelativeLayout mRtProgress,ImageView btnDownload,ImageView btnView,int issueid,boolean bPrev)
        {
            this.mProgressbar=mProgressbar;
            this.mRtProgress=mRtProgress;
            this.issueid=issueid;
            this.bPrev=bPrev;
            this.btnView=btnView;
            this.btnDownload=btnDownload;
            attatch(act);
        }
        void attatch(Main_Page act)
        {
            activity=act;
            context=act;
        }
        void detatch()
        {
            activity=null;
        }
        @Override
        protected void onPreExecute() {
            // TODO Auto-generated method stub
            mRtProgress.setVisibility(View.VISIBLE);
            super.onPreExecute();
        }
        @Override
        protected void onPostExecute(String result) {
            // TODO Auto-generated method stub
            if(result!=null)
            {
                try{
                if(mRtProgress!=null)
                    mRtProgress.setVisibility(View.GONE);
                activity.UpdateDB(result,issueid,bPrev,btnDownload,btnView);
                }catch(Exception e){}
            }
            super.onPostExecute(result);
        }
        @Override
        protected void onProgressUpdate(Integer... values) {
            // TODO Auto-generated method stub
            mProgressbar.setProgress(values[0]);
            super.onProgressUpdate(values);
        }
        @Override
        protected String doInBackground(String... params) {
            // TODO Auto-generated method stub
            try{
                String File_Name=params[0].substring( params[0].lastIndexOf('/')+1, params[0].length() );
                File file = new File(context.getDir(AMI.strMainDir, Context.MODE_PRIVATE) + "/"+File_Name);
                if (!file.exists())
                {
                    file.createNewFile();
                    URL url=new URL(params[0]);
                    URLConnection con=url.openConnection();
                    con.connect();
                    int LengthOfFile=con.getContentLength();
                    InputStream input=new BufferedInputStream(url.openStream());
                    OutputStream output=new FileOutputStream(file);
                    byte data[]=new byte[1024];
                    int count = 0;
                    long total=0;
                    while((count=input.read(data))!=-1&&(!isCancelled()))
                    {
                        total+=count;
                        Log.d("total",total+"");
                        publishProgress((int)((total*100)/LengthOfFile));
                        output.write(data,0,count);
                    }
                    output.flush();
                    output.close();
                    input.close();
                }
                return File_Name;
            }catch(Exception ex){}
            return null;
        }

    }

0 个答案:

没有答案