kishidp kishidp - 1 year ago 117
Android Question

Load an image from assets folder

I am trying to load an image from the

folder and then set it to an
. I know it's much better if I use the*
for this, but the premise is I don't know the id of the image. Basically, I'm trying to dynamically load the image via its filename.

For example, I randomly retrieve an element in the
representing let's say a 'cow', now what my application would do is to display an image of a 'cow' via the
. This is also true for all element in the
. (The assumption is, for every element there is an equivalent image)

thanks in advance.


forgot the question, how do I load the image from the

Answer Source

If you know the filename in the code, calling this won't be a problem:

ImageView iw= (ImageView)findViewById(;  
int resID = getResources().getIdentifier(drawableName, "drawable",  getPackageName());

Your filename will be the same name as drawableName so you won't have to deal with assets.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download