I need to show an image by using the file name only, not from the resource id.
ImageView imgView = new ImageView(this); imgView.setBackgroundResource(R.drawable.img1);
I have the image img1 in the drawable folder. I wish to show that image from the file.
How can I do this?
You can use:
ImageView imgView = new ImageView(this); InputStream is = getClass().getResourceAsStream("/drawable/" + fileName); imgView.setImageDrawable(Drawable.createFromStream(is, ""));