In the onCreate event i make an asynchronous request to the facebook api :
Utility.mAsyncRunner.request(null, params1,
new myListener());
In myListener’s onComplete Event i would like to set the image in an imageview
public class PhotoDisplayListener extends BaseRequestListener {
@Override
public void onComplete(final String response, final Object state) {
//set my image with the url provided in the response
...parse json....
ImageView img = (ImageView)findViewById(R.id.img);
URL ulrn = new URL(photourl);
HttpURLConnection con = (HttpURLConnection)ulrn.openConnection();
InputStream is = con.getInputStream();
Bitmap bmp = BitmapFactory.decodeStream(is);
if (null != bmp){
img.setImageBitmap(bmp);
setImage(bmp);
}
else
System.out.println("The Bitmap is NULL");
}catch(Exception e){} catch (FacebookError e) {
// TODO Auto-generated catch block
e.printStackTrace();
showToast(e.getMessage());
}
}
}
the problem is that the imageview does not refresh with the new one set by me.
It sets it, by it doesn’t refresh it. If i lock and unlock the phone, the image appears as it should.
How can i force the refresh of the imageview?
Thanks!
You can’t update the UI thread from outside (another thread). I would recommend you to call instead a method on your activity to update the ImageView.
Article about this topic: Painless Threading