Skip to content

Instantly share code, notes, and snippets.

@r-trigo
Last active February 23, 2017 12:13
Show Gist options
  • Save r-trigo/37fca343ec7f078fac1887bc51f916ee to your computer and use it in GitHub Desktop.
Save r-trigo/37fca343ec7f078fac1887bc51f916ee to your computer and use it in GitHub Desktop.
private class LoadImageTask extends AsyncTask<String, Void, Bitmap> {
@Override
protected Bitmap doInBackground(String... image_url) {
URL[] myURL = new URL[1];
try {
myURL[0] = new URL(image_url[0]);
return BitmapFactory.decodeStream((InputStream) myURL[0].getContent());
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Bitmap bitmap) {
if (bitmap != null) {
//ImageView set image bitmap
iv_url.setImageBitmap(bitmap);
} else {
Toast.makeText(getApplicationContext(), "Error Loading Image !", Toast.LENGTH_SHORT).show();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment