android – how to set imageview src?

android – how to set imageview src?

Each image has a resource-number, which is an integer. Pass this number to setImageResource and you should be ok.

Check this link for further information:



To set image cource in imageview you can use any of the following ways. First confirm your image is present in which format.

If you have image in the form of bitmap then use


If you have image in the form of drawable then use


If you have image in your resource example if image is present in drawable folder then use


If you have path of image then use


android – how to set imageview src?

What you are looking for is probably this:

ImageView myImageView;
myImageView = mDialog.findViewById(;
String src = imageFileName

int drawableId = this.getResources().getIdentifier(src, drawable, context.getPackageName())

Let me know if this was helpful 🙂

Leave a Reply

Your email address will not be published.