There is an ImageView and a button. When button gets clicked an imageview should change the source(display another image) for 1 second and then go back to default source which is defined in layout file.
How to do that???
Thanks in advance
There is an ImageView and a button. When button gets clicked an imageview should change the source(display another image) for 1 second and then go back to default source which is defined in layout file.
How to do that???
Thanks in advance
change image when button clicked
ImageView image;
image.setImageResource(R.drawable.newimage);
and after 2 second change default image
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
ImageView image;
image.setImageResource(R.drawable.defaultimage);
}
}, 2000);
To change the imageView content you use :
yourImageView.setImageDrawableResouce(R.drawable.imgTemp);
To count 1 second, you can use
final ScheduledExecutorService exec = Executors.newScheduledThreadPool(1);
exec.schedule(new Runnable(){
@Override
public void run(){
setYourImageView();//return the image to the original one
}
}, 1, TimeUnit.SECONDS);
To do it in the UI thread you can use
runOnUiThread(new Runnable() {
public void run() {
yourImageView.setImageDrawableResouce(R.drawable.imgTemp);
}
}
});