How To Force The Change The Image Of A View Immediately After Calling Setimageresource?
I'm trying to change the image of a ImageView immediately after I click it. I tried using .setImageDrawable and calling .invalidate() on that view, without any success. I'm proba
Solution 1:
You can use sendMessageDelayed()
method of handler
to perform any task at a delay of some specific amount of time. and write the logic to setImageDrawable inside that handler
See the sample code
@OverridepublicvoidonClick(View v) {
Messagemsg=newMessage();
photoGridHandler.sendMessageDelayed(msg, 2000);// delay of 2000 milisecond = 2 second
}
privateHandlerphotoGridHandler=newHandler() {
@OverridepublicvoidhandleMessage(Message msg) {
photoGrid.setImageDrawable(myImage);
};
};
Solution 2:
Try using image.setBackgroundResource(R.drawable.newimage);
. Place both the images in your drawable
folder
Solution 3:
I had similar issues when mixing the UI thread and computations thread. I would recommend trying an AsyncTask and pass it imageView. Do your computations in the doInBackground of the asynctask and then in the onPostExecute change the image.
http://developer.android.com/reference/android/os/AsyncTask.html
Post a Comment for "How To Force The Change The Image Of A View Immediately After Calling Setimageresource?"