KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have a question that seems easy but I cannot seem to get it to work properly. I have a zip file within my 'assets' folder that I need to unzip and I have a ProgessBar in which I want to display to the user how the progress is going. I have everything working but I want to set the ProgessBar max value to be the number of files within the zip file. The number of files within this folder will sometimes change so I want the ProgessBar to be relative to how many files are contained within the zip. I'm using the ZipInputStream -API but does not seem there is a way to get the number of files within the zip file. The only way I can of think of is doing this: ZipInputStream zin = new ZipInputStream(getAssets().open( "myFile.zip")); int numFiles = 0; int increment = 0; while (zin.getNextEntry() != null) { numFiles++; } ZipEntry ze = null; //Set the Max..value here.. progessBar.setMax(numFiles); while ((ze = zin.getNextEntry()) != null) { increment++; progessBar.setProgress(increment); } This works but having two while loops seems a bit redundant which are basically doing the same thing. I know that there is a ZipFile -API which has a size() -method, but it requires a path to the file and since my file is located within the 'assets' folder I am pretty sure the only way to read from this directory is by streaming. Is there a way for me to accomplish this?
Tags (comma-separated)
Save Edits
Cancel