Android > DefaultHttpClient - URL을 이용해서 이미지 다운로드 (멀티쓰레드 이용)
등록일 : 2017-07-06 17:37
조회수 : 93,380
멀티쓰레드를 이용해서 서버의 이미지를 폰으로 읽어드리는 방법입니다.
소스를 다운받으신후 테스트 바랍니다.
SnowPhotoViewer.java 소스파일입니다.
package snow.photo.viewer;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.GridView;
public class SnowPhotoViewer extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btnDownload = (Button)findViewById(R.id.btnButton);
btnDownload.setOnClickListener(myButtonClick);
}
Button.OnClickListener myButtonClick = new Button.OnClickListener()
{
public void onClick(View v)
{
String [] strURLS = {"http://cfile25.uf.tistory.com/image/112CA2274C2220D2B47CB1",
"http://cfile24.uf.tistory.com/image/110475474D666C30382331",
"http://cfile24.uf.tistory.com/image/110475474D666C30382331",
"http://cfile24.uf.tistory.com/image/110475474D666C30382331",
};
GridView gv = (GridView)findViewById(R.id.gvGridView);
ImageAdapter imgAdapter = new ImageAdapter(strURLS);
gv.setAdapter(imgAdapter);
}
};
}
전체 프로젝트 파일 첨부합니다.
SnowPhotoViewer.zip