I have an XML file with a list of image names (plus other data)
Example: image1, image2, image3, etc
I am able to load the XML file, parse the results, and loop through the image names. What I’m having trouble with is retrieving the images from the drawable folder and displaying them on the app.
When the script loops it pulls each image name (ie image1, image2, etc) that matches the image in the drawables folder (ie image1.png, image2.png, etc). It assigns this name to the ImageNameInXml string. I want to use this string to assign the ImageView to that drawable and then repeat this (via the loop already in place) for each image showing all images on the screen.
String ImageNameInXml = ghostCamLocation.getAttributeValue(null, XML_TAG);
ImageView img = (ImageView) findViewById(R.id.MyImageView);
int resId = getResources().getIdentifier(ImageNameInXml , "@drawable/"+ImageNameInXml, getPackageName());
imgGhostCamLocationTmbnail.setImageResource(resId);
The found the above code on stackoverflow to load an image by a string name, but I can’t seem to get it to work.
I appreciate the help.
Take care,
Shannon
try this.