I want to show other image in ImageView within 3 second, after that rollover old image. The code:
OnClickListener oc = new OnClickListener() {
@Override
You are blocking the UI thread. Thus during the sleep command, the screen won't refresh. What you need is to schedule a non-blocking delayed call to a function which changes image resource. Here is a modified code that would do such a thing:
Handler mHandler = new Handler(); /*handler declared in your Activity thread, I assume*/
OnClickListener oc = new OnClickListener() {
@Override
public void onClick(View v) {
ImageView iv = (ImageView)v;
iv.setImageResource(img2_id);
mHandler.postDelayed(new Runnable(){
public void Run(){
iv.setImageResource(img1_id);
}
},3000);
}
}
myImageView.setOnClickListener(oc);