Advertisement
Guest User

meow

a guest
Oct 23rd, 2014
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. package com.example.testing;
  2.  
  3. import java.io.InputStream;
  4.  
  5. import android.os.AsyncTask;
  6. import android.os.Bundle;
  7. import android.app.Activity;
  8. import android.graphics.Bitmap;
  9. import android.graphics.BitmapFactory;
  10. import android.util.Log;
  11. import android.view.Menu;
  12. import android.widget.ImageView;
  13.  
  14. public class MainActivity extends Activity {
  15.  
  16. @Override
  17. protected void onCreate(Bundle savedInstanceState) {
  18. super.onCreate(savedInstanceState);
  19. setContentView(R.layout.activity_main);
  20. new DownloadImageTask((ImageView) findViewById(R.id.imageView1))
  21. .execute("http://www.cuckooforcoupondeals.com/wp-content/uploads/2011/07/285570_10150320990546678_777421677_9426881_5269383_n.jpg");
  22. }
  23.  
  24.  
  25. @Override
  26. public boolean onCreateOptionsMenu(Menu menu) {
  27. // Inflate the menu; this adds items to the action bar if it is present.
  28. getMenuInflater().inflate(R.menu.main, menu);
  29. return true;
  30. }
  31.  
  32.  
  33.  
  34. private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
  35. ImageView bmImage;
  36.  
  37. public DownloadImageTask(ImageView bmImage) {
  38. this.bmImage = bmImage;
  39. }
  40.  
  41. protected Bitmap doInBackground(String... urls) {
  42. String urldisplay = urls[0];
  43. Bitmap mIcon11 = null;
  44. try {
  45. InputStream in = new java.net.URL(urldisplay).openStream();
  46. mIcon11 = BitmapFactory.decodeStream(in);
  47. } catch (Exception e) {
  48. Log.e("Error", e.getMessage());
  49. e.printStackTrace();
  50. }
  51. return mIcon11;
  52. }
  53.  
  54. protected void onPostExecute(Bitmap result) {
  55. bmImage.setImageBitmap(result);
  56. }
  57. }
  58.  
  59.  
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement