I'm working with Android currently, coding in Eclipse.
I'm trying to set an image (pic1) in XML and this picture is replaced with another image (pic2) when a service is started(and reverts back when the service is stopped). Is this possible? (VERY new to开发者_运维技巧 this..) I realize i can set an image and how, I just can't find an answer to how to make the change between pic1 -> pic2. Help?
Thanks in advance, and I apologize if anything is unclear or just plain dumb. -Bobby
You don't need to use two ImageViews
for accomplishing this.
You can get the reference to your ImageView
using the findViewById
method of your current activity, and once you have it, you can change it's resource drawable (it will show the new image):
final ImageView imageView = (ImageView)findViewById(R.layout.connection_image);
if (serviceStarted)
imageView.setImageResource(R.drawable.started);
else
imageView.setImageResource(R.drawable.stopped);
精彩评论