Last active
February 23, 2017 12:13
-
-
Save r-trigo/37fca343ec7f078fac1887bc51f916ee to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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