Get a resource id with a known resource name(String,id,Drawable)

by Wednesday, October 02, 2013 0 comments
Get a resource id with any of known resource name like string,drawable, id... Using getIdentifier Return a resource identifier for the given resource name. A fully qualified resource name is of the form "package:type/entry". The first two components (package and type) are optional if defType and defPackage, respectively, are specified here.

Example: defType = "string" (or) "id" (or) "drawable"
                idStr = if drawable like R.drawable.ic_add means then "ic_add"

 public int getresId(String defType, String idStr){  
           int resId = this.getResources().getIdentifier(idStr, defType, this.getPackageName());  
           return resId;  

karthik nagarajan


Welcome to Android-Action Blog. I’m a normal guy, who is passionate about Mobile Coding. Here I am writing about Android. Happy learning


Post a Comment