I need to display an image which I save under res/drawable folder. I get the image name from a web service call and I try to find this image in the drawable folder using the following code
ImageView backgroundImage = (ImageView) findViewById(R.id.ivFormBackgroundImage);
Resources res = getResources();
String mDrawableName = formSummary.backgroundImageName;
int resID = res.getIdentifier(mDrawableName , "drawable", getPackageName());
Drawable drawable = res.getDrawable(resID );
backgroundImage.setImageDrawable(drawable );
The resID always returns 0 and i wonder if it is because of the packagename. I have set my package name to be package=”com.x.y.z.classes.ui.screens” in the Android_Manifest file, but the image is in res/drawable. Any help on how to get the path of the image is much appreciated.
thanks…
It looks like you are doing it right, but make sure that the package name you specify matches the package name where the actual R class resides.