First, the name of your image is myimage . So what you need to do is go to Drawable and save the image name myimage .
Now suppose that you only know the name of the image, and you need to access it. Use the snippet below to access it,
what you did right, make sure you save the name of the image that you are going to use inside the encoding.
public static int getResourceId(Context context, String name, String resourceType) { return context.getResources().getIdentifier(toResourceString(name), resourceType, context.getPackageName()); } private static String toResourceString(String name) { return name.replace("(", "") .replace(")", "") .replace(" ", "_") .replace("-", "_") .replace("'", "") .replace("&", "") .toLowerCase(); }
In addition to this, you must ensure that there are no empty spaces or case sensitivity.
Venky Jul 31 '12 at 10:25 2012-07-31 10:25
source share