AsyncTask
インターネットからいくつかのファイルをダウンロードするによって管理されるプログレスバーがあります。
private class DownloadImgs extends AsyncTask<Void, String, Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
showDialog(progress_bar_type);
}
@Override
protected Void doInBackground(Void ...params) {
for(GetCountry gc : listCountry){
getdownloadedFiles(gc.getUrl());}
return null;
}
protected void onProgressUpdate(String... progress) {
pDialog.setProgress(Integer.parseInt(progress[0]));
}
@Override
protected void onPostExecute(Void result) {
dismissDialog(progress_bar_type);
}
ファイルをダウンロードできるようにする方法:
public void getdownloadedFiles(String url)
{
int count;
try {
URL urlImg = new URL(url);
URLConnection connection = urlImg.openConnection();
connection.connect();
int lenghtOfFile = connection.getContentLength();
InputStream input = new BufferedInputStream(urlImg.openStream(), 8192);
OutputStream output = new FileOutputStream(folder+"/"+name);
byte data[] = new byte[1024];
long total = 0;
while ((count = input.read(data)) != -1) {
total += count;
publishProgress(""+(int)((total*100)/lenghtOfFile));
output.write(data, 0, count);
}
output.flush();
output.close();
input.close();
} catch (Exception e) {
e.getMessage();
}
}
このコードはうまく機能しますが、問題は、ダウンロードされた各ファイルに独自のプログレスバーがあることです。ダウンロードされたすべてのファイルに対して1つのプログレスバーだけが必要です。
どうすればこれを達成できますか?どうもありがとうございます