Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private class AsyncTask extends AsyncTask<String , Integer , Bitmap>{
- private Context mContext;
- private LinearLayout linearLayout;
- Bitmap bit;
- public void setView(LinearLayout ll,Context c){
- linearLayout = ll;
- mContext = c;
- }
- @Override
- protected Bitmap doInBackground(String... params) {
- //執行中 在背景做事情
- for (String urlStr : params) {
- try {
- System.out.println(urlStr);
- InputStream img_stream;
- URL img_url = new URL(urlStr);
- img_stream = img_url.openStream();
- bit = BitmapFactory.decodeStream(img_stream);
- } catch (Exception e) {
- e.printStackTrace();
- }
- publishProgress();
- }
- return null;
- }
- @Override
- protected void onProgressUpdate(Integer... values) {
- //執行中 可以在這邊告知使用者進度
- super.onProgressUpdate(values);
- ImageView iv = new ImageView(mContext);
- iv.setScaleType(ImageView.ScaleType.CENTER_CROP);
- iv.setImageBitmap(bit);
- linearLayout.addView(iv);
- }
- }
Add Comment
Please, Sign In to add comment