View.post () not called?

I am making an image downloader to load images into lists, so in order for it to be smooth, everything should be done in the background thread, except setting the image to the view. The problem is that Runnable in the code below sometimes fails. I call the setImage method from background threads.

protected void setImage(final ImageView img, final Bitmap bm, String hash) { img.setTag(TAG_RESPONSE, hash); Log.v(TAG, "setting image bitmap1"); //TODO: here is the bug - sometimes the runnable below is not called img.post(new Runnable() { @Override public void run() { Log.v(TAG, "setting image bitmap2"); img.setImageBitmap(bm); img.invalidate(); } }); } 

Anyone have any ideas what I'm doing wrong?

+8
android
source share
1 answer

According to the documentation, a message (...) should be called from threads other than the UI only when the view is attached to the window. This can be a problem.

+13
source share

All Articles