Skip to content Skip to sidebar Skip to footer

Trying To Get Drawable Resource Id From Its Name In Android

I have a resource file like this: strings.xml My Category 01My Category 02

Solution 1:

One simple solution would be to parse the string and get only the image name as below.

String[] Image1 = array[1][1].split("/");
Strings= Image1[Image1.length-1].replace(".png","").trim();

intresID=this.context.getResources().getIdentifier(s , "drawable", this.context.getPackageName());

Solution 2:

array[1][1] is the path to the resource. You must specify a name.See http://developer.android.com/reference/android/content/res/Resources.html#getIdentifier%28java.lang.String,%20java.lang.String,%20java.lang.String%29

Post a Comment for "Trying To Get Drawable Resource Id From Its Name In Android"