인터넷 URL형식을 가져와서 이미지를 이미지뷰에 가져오려고 하는데 되지를 않네요..ㅜㅜ
소스코드는 인터넷에서 본걸로 했는데
뭐가 문제인지 잘 되지 않네요 .ㅜㅜㅜ
<액티비티>
findViewById(R.id.btn02).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//정보가저오기
Cursor cursor = handler.select();
startManagingCursor(cursor);
while (cursor.moveToNext()) {
int _id =cursor.getInt(cursor.getColumnIndex("_id"));
String name =cursor.getString(cursor.getColumnIndex("name"));
String age =cursor.getString(cursor.getColumnIndex("age"));
String phone =cursor.getString(cursor.getColumnIndex("phone"));
String addr =cursor.getString(cursor.getColumnIndex("addr"));
String img=cursor.getString(cursor.getColumnIndex("image"));
tv01.setText("seq="+_id+"//"+"이름="+name +"//"+"나이="+age+"//"+"폰="+phone+"//"+"주소="+addr+"//"+"이미지="+img);
Bitmap bitmap=null;
try {
URL url=new URL(img);
//웹사이트에 접속
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
//데이터 가져옴
int imageSize=conn.getContentLength();
//스트림에 넣어줌
BufferedInputStream bis=new BufferedInputStream(conn.getInputStream(),imageSize);
//비트맵에 넣어줌
bitmap=BitmapFactory.decodeStream(bis);
bis.close();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
img01.setAdjustViewBounds(true);
img01.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
img01.setScaleType(ImageView.ScaleType.FIT_XY);
img01.setImageBitmap(bitmap);
\ }
}
});
}
}
<메인.xml>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="${packageName}.${activityClass}" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/tv01"
android:layout_below="@+id/btn01"
android:layout_marginTop="99dp"
android:src="@drawable/abc_list_selector_disabled_holo_light" />
</RelativeLayout>