Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. private class LoadImageTask extends AsyncTask<String, Void, Bitmap> {
  2.  
  3. @Override
  4. protected Bitmap doInBackground(String... image_url) {
  5. URL[] myURL = new URL[1];
  6. try {
  7. myURL[0] = new URL(image_url[0]);
  8. return BitmapFactory.decodeStream((InputStream) myURL[0].getContent());
  9. } catch (IOException e) {
  10. e.printStackTrace();
  11. }
  12. return null;
  13. }
  14.  
  15.  
  16. @Override
  17. protected void onPostExecute(Bitmap bitmap) {
  18. if (bitmap != null) {
  19. //ImageView set image bitmap
  20. iv_url.setImageBitmap(bitmap);
  21. } else {
  22. Toast.makeText(getApplicationContext(), "Error Loading Image !", Toast.LENGTH_SHORT).show();
  23. }
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement