Ratna
Ratna

Reputation: 33

Replace images in android

I'm new to android. I have an image in res/values/drawable-hdpi named ic_launcher i want to replace this image by another image stored in another directory of the same project. I want to replace by using the java code. so please help me to sort out this problem

Upvotes: 2

Views: 180

Answers (3)

Pratik Dasa
Pratik Dasa

Reputation: 7439

Try below code:

imageView.setImageResource(R.drawable.YOURIMAGE);

// If incase your image would not change then add below line.

imageView.invalidate();

Upvotes: 0

MUHAMMAD WASIM
MUHAMMAD WASIM

Reputation: 191

you can do it with:

imgView.setImageResource(R.drawable.imgName);

Upvotes: 0

Blaze Tama
Blaze Tama

Reputation: 10948

Use myImageView.setImageResource(R.drawable.your_image); and call myImageView.invalidate() if the resource is not changed.

Upvotes: 1

Related Questions