How to change the image of an Imageview dynamically

Asked

Viewed 3,190 times

6

Hello, I need help changing an image dynamically

Follows my code:

st = (ImageView) findViewById(R.id.imageView4);
int RID = this.getApplicationContext().getResources().getIdentifier(Bundle_img, "drawable", getPackageName());
st.setImageResource(RID );

the above code is not overwriting the previous image.

  • How is String coming Bundle_img ?

  • Bundle_img = "red"

  • 2

    Friend Thanks, I already found the problem. I committed an operational failure. : D My image is with ic_situacao_+(Bundle_img) Thanks

  • 1

    Put the solution here to help others in the future. obg

1 answer

0

Try to use getResources().getDrawable(R.drawable.nome_imagem).

Example:

Drawable drawable= getResources().getDrawable(R.drawable.nome_imagem);
img.setImageDrawable(drawable);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.