I don't know if this is the best solution, but you can make a Hashtable that maps image names to resources.
Hashtable map;
map.put("temp1", R.drawable.temp1)
and then you can load the ImageView from drawable.
String imageName = "temp" + n;
Drawable d = getResources().getDrawable((int)map[imageName]);
ImageView i = new ImageView(this);
i.setImageResource(d);
source
share