메뉴 건너뛰기

조회 수 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.}


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


List of Articles
번호 제목 날짜 조회 수
97 하이브리드 앱에서의 세션관리(로그인 상태 유지) 2018.12.27 4998
96 WebView를 사용할때 HttpClient를 이용한 Session 유지 2018.12.27 4380
95 안드로이드 - 에디트텍스트(EditText) 사용법 정리 file 2021.03.29 2754
94 WebView에서 카메라 및 이미지 업로드 (선택적용가능) file 2020.12.14 2690
93 구글맵으로 GPS 현재위치 실시간 연동하기 file 2020.12.14 2440
92 위젯 업데이트 주기 빠르게 하기 2018.10.02 2142
91 안드로이드 - 네비게이션 드로어(Navigation Drawer)를 활용하여 슬라이드 메뉴 구현하기 file 2021.04.01 1858
90 MediaPlayer 클래스 사용법 file 2018.10.02 1803
89 Android Studio에서 SQLCipher 라이브러리 추가 방법 file 2018.10.02 1776
88 안드로이드 - 날짜 및 시간 정보 입력받기 (DatePickerDialog / TimePickerDialog) file 2021.04.01 1762
87 안드로이드 WebView 에서 tel: 이 되지않는 경우. 2018.10.02 1633
86 Apk manager 이용해 Decompile (디컴파일) 하기 file 2021.03.16 1620
85 안드로이드 - BottomNavigationView 사용하여 하단 메뉴 만들기 file 2021.04.02 1436
84 Volley 로 웹요청하고 응답받기2 - Post방식 , 로그인-회원가입 (php,mysql 연동) file 2020.12.14 1430
83 안드로이드 - 타이머(Timer) 구현하기 2021.04.01 1368
82 [하이브리드앱] userAgent를 이용해서 웹 / 앱 접속 구분하기 2021.09.30 1282
81 안드로이드 - switch를 사용법 및 구현 file 2021.04.02 1280
80 안드로이드 - 텍스트뷰(TextView) 사용법 정리 file 2021.03.31 1247
79 안드로이드 - KeyEvent(키 이벤트) 처리 file 2021.04.02 1211
78 WebView 작업할때 Net::ERR_UNKNOWN_URL_SCHEME 에러 발생할때 (전화걸기,문자보내기 안된다) 2020.12.14 1067
Board Pagination Prev 1 ... 4 5 6 7 8 9 10 11 12 13 Next
/ 13

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

© k2s0o1d4e0s2i1g5n. All Rights Reserved