Skip to content

Instantly share code, notes, and snippets.

@Subtle-fox
Last active July 12, 2017 13:36
Show Gist options
  • Save Subtle-fox/f1d79b7bf87d0fc12f3d9c597975e23c to your computer and use it in GitHub Desktop.
Save Subtle-fox/f1d79b7bf87d0fc12f3d9c597975e23c to your computer and use it in GitHub Desktop.
Obtain resourse identifier by it's name
public static int getResIdByName(Context appContext, String resType, String name) {
return appContext.getResources().getIdentifier(name, resType, appContext.getPackageName());
}
// usage:
getResIdByName(appContext, "string", name);
getResIdByName(appContext, "drawable", name);
getResIdByName(appContext, "layout", name);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment