Guest User

Untitled

a guest
Feb 15th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. private class AsyncTask extends AsyncTask<String , Integer , Bitmap>{
  2. private Context mContext;
  3. private LinearLayout linearLayout;
  4. Bitmap bit;
  5.  
  6.  
  7. public void setView(LinearLayout ll,Context c){
  8. linearLayout = ll;
  9. mContext = c;
  10. }
  11.  
  12. @Override
  13. protected Bitmap doInBackground(String... params) {
  14. //執行中 在背景做事情
  15. for (String urlStr : params) {
  16. try {
  17. System.out.println(urlStr);
  18.  
  19.  
  20. InputStream img_stream;
  21. URL img_url = new URL(urlStr);
  22. img_stream = img_url.openStream();
  23. bit = BitmapFactory.decodeStream(img_stream);
  24. } catch (Exception e) {
  25. e.printStackTrace();
  26. }
  27. publishProgress();
  28. }
  29. return null;
  30. }
  31.  
  32. @Override
  33. protected void onProgressUpdate(Integer... values) {
  34. //執行中 可以在這邊告知使用者進度
  35. super.onProgressUpdate(values);
  36. ImageView iv = new ImageView(mContext);
  37. iv.setScaleType(ImageView.ScaleType.CENTER_CROP);
  38. iv.setImageBitmap(bit);
  39. linearLayout.addView(iv);
  40. }
  41.  
  42. }
Add Comment
Please, Sign In to add comment