I have several string arrays stored in my database that contain file names. I want to loop through this array to return the files one by one that are stored in the internal storage. Example of one of the array:
[["12","21","31"],["empty","22","32"],["13","23","33"]]// this is the array unmodified
Below is the code I have now but just gives me an index error as the index is 12 at the start because of the array begins at 12.
layout = layout.replaceAll("\"empty\",?", "").replaceAll("[\"\\]\\
[\"]+","").replaceAll("^\"|\"$", ""); //this removes the "empty" string
String[] layoutArray = layout.split(",");
int rows = 3;
int columns = 3;
int layoutElement = 0;
try {
for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
// get the image from the internal storage
int imageIndex = Integer.valueOf(layoutArray[layoutElement]) - 1;
String imageFile = layoutArray[imageIndex];
Bitmap image = BitmapFactory.decodeFile(new File(getFilesDir(), imageFile).getAbsoluteFile().toString());
mImageList.add(new Grid(getApplicationContext(), i, j, image, imageFile));
layoutElement++;
}
}
} catch (Exception e) {
e.printStackTrace();
}
I know the code I have is completely wrong in logic but I need help with this and can't get my head around it. each of the array values has a file name stored by that number, I removed "empty" because it is not needed. My end goal is to place these files(that are images) into a grid view.