tags:

views:

48

answers:

2

how can I change the background of an ImageView from java? I have an ImageView and at a certain point I need to change the image that it displays (set in the styles). I tried to do it like this:

placeHolder.setImageDrawable(myDrawb);

but it looks like the old image remains there and it is partially covered but the new one (which in my case has different shape).

hope you guys can help!

cheers

A: 

Clear the background image with:

placeHolder.setBackgroundResource( 0 );
drawnonward
yes! that was it! so basically the android doesnt authomatically substitute the old with the new one ... it stacks them up unless you use setBackgroundResource. very usefull thanks
nourdine
The background is independent of the content. You are setting the content with setImageDrawable but leaving the background.
drawnonward
A: 

Alternatively you should set the Src of the ImageView in xml instead of setting the Background. I think this is the "right" way anyhow.

CaseyB
I cant touch the XML! I load images from the web and I need to chuck them in their placeholders when the download of the image is finished
nourdine