Reputation: 2981
I am making an Image loader for loading images into lists - so in order it to be smooth, everything needs to run in the background thread except setting the image to the view. The problem is that the Runnable in the code bellow is sometimes not executed. I am calling 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 has any ideas what am I doing wrong?
Upvotes: 17
Views: 5424
Reputation: 34530
According to the documentation, the post(...) should be called from non-UI threads only when the View is attached to a window. This could be the problem.
Upvotes: 26