메뉴 건너뛰기

조회 수 8992 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄 첨부
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄 첨부


SnowPhotoViewer.zip

 

[안드로이드] URL을 이용해서 이미지 다운로드 하기 - http://snowbora.com/402



그리고, 이 글의 원문은 

입니다. 영어가 되신다면 원문을 보는 것도 좋은 방법(?)입니다. +_+


원문에 가면 소스코드도 다운 받아서 돌려볼 수 있습니다. 그 중 중요한 파일 2가지는 여기에 올려둡니다.
(원본 파일입니다.)




물론, 저는 제가 쓰기 편하도록 코드들을 조금 수정했습니다.

수정한 ImageAdapter.java 파일은 다음과 같습니다.

01./*
02. * Copyright (C) 2010 The Android Open Source Project
03. *
04. * Licensed under the Apache License, Version 2.0 (the "License");
05. * you may not use this file except in compliance with the License.
06. * You may obtain a copy of the License at
07. *
09. *
10. * Unless required by applicable law or agreed to in writing, software
11. * distributed under the License is distributed on an "AS IS" BASIS,
12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13. * See the License for the specific language governing permissions and
14. * limitations under the License.
15. */
16. 
17.package snow.photo.viewer;
18. 
19.import android.view.View;
20.import android.view.ViewGroup;
21.import android.widget.BaseAdapter;
22.import android.widget.GridView;
23.import android.widget.ImageView;
24. 
25.public class ImageAdapter extends BaseAdapter {
26.    private final ImageDownloader imageDownloader = new ImageDownloader();
27.    private String[] strURLList;
28.     
29.    public ImageAdapter(String _strURLList[])
30.    {
31.        if (_strURLList != null)
32.        {
33.            strURLList = _strURLList;
34.        }
35.    }
36.     
37.    public int getCount()
38.    {
39.        return strURLList.length;
40.    }
41. 
42.    public String getItem(int position)
43.    {
44.        return strURLList[position];
45.    }
46. 
47.    public long getItemId(int position)
48.    {
49.        return strURLList[position].hashCode();
50.    }
51. 
52.    public View getView(int position, View view, ViewGroup parent)
53.    {
54.        if (view == null)
55.        {
56.            view = new ImageView(parent.getContext());
57.            view.setLayoutParams(new GridView.LayoutParams(100, 100));
58.            view.setPadding(5, 5, 5, 5);
59.        }
60. 
61.        imageDownloader.download(strURLList[position], (ImageView)view);
62.         
63.        return view;
64.    }
65. 
66.    public ImageDownloader getImageDownloader()
67.    {
68.        return imageDownloader;
69.    }
70.}


그리고 액티비티 내용은 다음과 같습니다.

01.package snow.photo.viewer;
02. 
03.import android.app.Activity;
04.import android.os.Bundle;
05.import android.view.View;
06.import android.widget.Button;
07.import android.widget.GridView;
08. 
09.public class SnowPhotoViewer extends Activity {
10.    /** Called when the activity is first created. */
11.    @Override
12.    public void onCreate(Bundle savedInstanceState)
13.    {
14.        super.onCreate(savedInstanceState);
15.        setContentView(R.layout.main);
16.         
17.        Button btnDownload = (Button)findViewById(R.id.btnButton);
18.        btnDownload.setOnClickListener(myButtonClick);
19.    }
20.     
21.    Button.OnClickListener myButtonClick = new Button.OnClickListener()
22.    {
23.        public void onClick(View v)
24.        {
25.            String [] strURLS = {"http://cfile25.uf.tistory.com/image/112CA2274C2220D2B47CB1",
26.                                "http://cfile24.uf.tistory.com/image/110475474D666C30382331",
27.                                "http://cfile10.uf.tistory.com/image/160475474D666C343CD190",
28.                                };
29.             
30.            GridView gv = (GridView)findViewById(R.id.gvGridView);
31.            ImageAdapter imgAdapter = new ImageAdapter(strURLS);
32. 
33.            gv.setAdapter(imgAdapter);
34.        }
35.    };
36.}


전체 프로젝트 파일 첨부합니다.


  1. 안드로이드 소스 - 카메라 플래쉬(Flash, 후라시) 앱

    Date2015.06.29 Views8974
    Read More
  2. URL을 이용해서 이미지 다운로드 하기 (멀티 쓰레드 이용)

    Date2015.07.16 Views8992
    Read More
  3. [안드로이드] 리스트 뷰의 한 항목에 대한 컨텍스트 메뉴 만들기

    Date2015.09.04 Views9084
    Read More
  4. 화면 전환해도 데이터 유지 예제

    Date2015.07.26 Views9204
    Read More
  5. 다운로드 매니저(DownloadManager)에 대해 알아보자

    Date2015.07.01 Views9246
    Read More
  6. 안드로이드 팝업창 만들기(xml 내용 집어넣기)

    Date2015.07.23 Views9285
    Read More
  7. AndroidManifest에 선언한 메타데이터(meta-data) 가져오기

    Date2016.06.10 Views9322
    Read More
  8. 탭 뷰에 탭 추가하기, 아이콘 넣기

    Date2015.07.16 Views9361
    Read More
  9. [안드로이드] 팝업메뉴 사용법

    Date2015.09.03 Views9391
    Read More
  10. 안드로이드 php 로 mysql json 파싱 하기

    Date2014.08.28 Views9407
    Read More
  11. 카카오톡 분석하기 (2) - 카카오톡 암호화 함수 찾기

    Date2016.05.26 Views9601
    Read More
  12. ViewFlipper 사용하기

    Date2015.07.16 Views9631
    Read More
  13. 서버에서 이미지 불러와서 이미지뷰에 띄우기

    Date2015.07.16 Views9842
    Read More
  14. FTPClient 를이용하여 ftp상 서버에서 데이터 다운로드 편

    Date2014.08.28 Views9858
    Read More
  15. 네트워크 상태 변화 감지하기(BroadcastReceiver 사용)

    Date2015.07.16 Views9935
    Read More
  16. 안드로이드 채팅 소스 샘플

    Date2015.07.26 Views10088
    Read More
  17. 카카오톡 분석하기 (1) - sqlite 파해치기

    Date2016.05.26 Views10454
    Read More
  18. Android 간단한 회원 가입 폼 만들기 for Mac (PHPMyAdmin 이용)

    Date2015.07.10 Views10511
    Read More
  19. 블루투스 및 비콘 관련 정리

    Date2015.07.26 Views10829
    Read More
  20. WIFI 신호세기 강도 측정하기

    Date2014.08.28 Views11243
    Read More
Board Pagination Prev 1 ... 4 5 6 7 8 9 10 11 12 13 Next
/ 13

하단 정보를 입력할 수 있습니다

© k2s0o1d4e0s2i1g5n. All Rights Reserved