I’m trying to load a remote image from the server using the following code:
imageViewClient = (ImageView) findViewById(R.id.imageViewClient);
try
{
URL thumb_u = new URL(c.getImage());
Drawable thumb_d = Drawable.createFromStream(thumb_u.openStream(), "src");
imageViewClient.setImageDrawable(thumb_d);
}
catch (Exception e)
{
}
The image is showing fine but when I put the code into a new thread, the image is not loaded.
The code is:
new Thread()
{
@Override
public void run()
{
//** Set imageview url
try {
URL thumb_u = new URL(c.getImage());
Drawable thumb_d = Drawable.createFromStream(
thumb_u.openStream(), "src");
imageViewClient.setImageDrawable(thumb_d);
}
catch (Exception e) {
}
}
}.start();
The image does not load, why not?
you will need to use Activity.runOnUiThread for changing from background thread as :