Reputation: 33
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
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
Reputation: 191
you can do it with:
imgView.setImageResource(R.drawable.imgName);
Upvotes: 0
Reputation: 10948
Use myImageView.setImageResource(R.drawable.your_image);
and call myImageView.invalidate()
if the resource is not changed.
Upvotes: 1