親愛なる Stackoverflowians
私はGridviewを持っています。各アイテムには、アイテムボタンのクリック時に水平の進行状況バーが表示されるように設定されています
私は asyncTask を使用してそれを行いますが、今私の問題は 1) 進行中に上下にスクロールすると、位置の変更に関して表示されている他の項目でプログレスバーが進行します
2) アクティビティを変更し、このアクティビティに再び来ました。進行状況バーはそのグリッド項目には表示されませんが、バックグラウンドで実行中の進行状況は Logcat で確認します。
ここに私のプロセスのサンプル
その進行状況のダウンロードのコードは次のとおりです
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;
}
}