how to set imageview src?

后端 未结 3 1058
梦如初夏
梦如初夏 2021-02-02 07:15

I have an image view and a string src. I want to set the imageview source to the string src that I have, but am unable to do so beacuse the method expects an i

相关标签:
3条回答
  • 2021-02-02 07:24

    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:
    http://developer.android.com/guide/topics/resources/accessing-resources.html

    e.g.:

    imageView.setImageResource(R.drawable.myimage);
    
    0 讨论(0)
  • 2021-02-02 07:26

    What you are looking for is probably this:

    ImageView myImageView;
    myImageView = mDialog.findViewById(R.id.image_id);
    String src = "imageFileName"
    
    int drawableId = this.getResources().getIdentifier(src, "drawable", context.getPackageName())
    popupImageView.setImageResource(drawableId);
    

    Let me know if this was helpful :)

    0 讨论(0)
  • 2021-02-02 07:37

    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

    imageview.setImageBitmap(bm);
    

    If you have image in the form of drawable then use

    imageview.setImageDrawable(drawable);
    

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

    imageview.setImageResource(R.drawable.image);
    

    If you have path of image then use

    imageview.setImageURI(Uri.parse("pathofimage"));
    
    0 讨论(0)
提交回复
热议问题