본문 바로가기

Tip

[안드로이드] 이미지뷰에 url로 imageView 넣기

1) AndroidManifest.xml

<uses-permission android:name="android.permission.INTERNET" />

 

2) 샘플소스

 

public void getDetailItem(String sn) {
Call<ResponseBody> call = app.retrofitAPI.getDetailItem(sn);
call.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
try {
if (response.code() == 200) {
String json = response.body().string();
List<ShoppingDetail> list = Arrays.asList(new ObjectMapper().readValue(json, ShoppingDetail[].class));

editText8.setText(list.get(0).getItm_nm());
editText9.setText(list.get(0).getItm_qy());
editText10.setText(list.get(0).getItm_unit());
editText11.setText(list.get(0).getItm_pc());
editText12.setText(list.get(0).getReffer_matter());

String link = replaceFileName(call.request().url() + list.get(0).getFile_cours());

Thread thread = new Thread() {
@Override
public void run() {
try {
URL url = new URL(getString(R.string.baseUrl) + link);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoInput(true);
conn.connect();

InputStream is = conn.getInputStream();
bitmap = BitmapFactory.decodeStream(is);
} catch (Exception e) {
e.printStackTrace();
}
}
};
thread.start();

try {
thread.join();
imageView1.setImageBitmap(bitmap);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}

@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
Log.e("Retrofit Call :: ", "onFailure : getDetailItem");
}
});
}

 

 

 

감사합니다.

출처 : inma.tistory.com/64