Sometimes, it becomes necessary to have resource ID by name of the image. Below code works great for doing this
references:
http://stackoverflow.com/questions/3042961/how-do-i-get-the-resource-id-of-an-image-if-i-know-its-name
try {
Class res = R.drawable.class;
Field field = res.getField("drawableName");
int drawableId = field.getInt(null);
}
catch (Exception e) {
Log.e("MyTag", "Failure to get drawable id.", e);
}
http://stackoverflow.com/questions/3042961/how-do-i-get-the-resource-id-of-an-image-if-i-know-its-name
No comments:
Post a Comment