Hello, I need to implement ProgressDialog while the file is being extracted.
My extraction code is next. Now I just need to implement ProgressDialog
, remembering that the code I've tried has been tried to be implemented ProgressDialog
by me, but it did not work, it just gets Toast
:
private Button et1;
private ProgressDialog pDialog;
...
et1 = (Button) findViewById(R.id.btn1);
pDialog = new ProgressDialog(this);
pDialog.setMessage("Extraindo arquivo...");
pDialog.setCancelable(false);
et1.setOnClickListener(new View.OnClickListener(){
public void onClick(View v1){
etap1();
}
});
...
public void etap1(){
showpDialog(); <--
String zipFilePath = Environment.getExternalStorageDirectory()
.getAbsolutePath()+"/";
unpackZip(zipFilePath, "arquivo.zip");
}
private boolean unpackZip(String path, String zipname) {
InputStream is;
ZipInputStream zis;
try {
String filename;
is = new FileInputStream(path + zipname);
zis = new ZipInputStream(new BufferedInputStream(is));
ZipEntry mZipEntry; byte[] buffer = new byte[1024];
int count;
while ((mZipEntry = zis.getNextEntry()) != null) {
filename = mZipEntry.getName();
if (mZipEntry.isDirectory()) {
File fmd = new File(path + filename);
fmd.mkdirs();
continue;
}
FileOutputStream fout = new FileOutputStream(path + filename);
while ((count = zis.read(buffer)) != -1) {
fout.write(buffer, 0, count);
}
fout.close(); zis.closeEntry();
Toast.makeText(getApplicationContext(), "Extraído com sucesso",
Toast.LENGTH_SHORT).show();
}
hidepDialog(); <--
zis.close();
} catch (IOException e) { e.printStackTrace();
return false;
}
hidepDialog(); <--
return true;
}
private void showpDialog() { <--
if (!pDialog.isShowing())
pDialog.show();
}
private void hidepDialog() { <--
if (pDialog.isShowing())
pDialog.dismiss();
}
The file is extracted without problems, there are no errors in the extraction code, only ProgressDialog
does not appear.
Can anyone help me find the error?
Thank you!