I have this code in Android Studio:
for (ArrayList<Bitmap> arr : imgs) {
for (Bitmap img : arr) {
if (img != null) {
arrayList.add(img.getHeight());
}
else {
arrayList.add(null);
}
}
heights.add(arrayList);
arrayList.clear();
}
With imgs declared and filled earlier and heights declared as an
ArrayList<ArrayList<Integer>>
What I get is:
[[58]]
[[null], [null]]
[[75], [75], [75]]
[[null], [null], [null], [null]]
[[1200], [1200], [1200], [1200], [1200]]
[[960], [960], [960], [960], [960], [960]]
[[960], [960], [960], [960], [960], [960], [960]]
[[612], [612], [612], [612], [612], [612], [612], [612]]
[[1632], [1632], [1632], [1632], [1632], [1632], [1632], [1632]]
And so on. Every time it doesn't add the value to the array but it replaces all the values in it with the new one. What's wrong?
ArrayListis working fine. Start by assuming it's your code that's not working.