You defined img_shelf
variable on the class and then you redefine it again in the loop (so it's instantiated only within the scope of the loop):
for (String themeName : list_theme) {
//prepare image in layout gallery
ImageView img_shelf = new ImageView(this);
...
}
This won't work as intended.
I'm not sure how you wanted to use it though as it seems that you create multiple ImageView
's but then attach OnClickListener
to only one of them. You will need to either move the code for OnClickListener
into the loop or create a variable - list of ImageView
on the class.