Пытаюсь добавить картинку из интернета в Bitmap в ImageView который находиться в SimpleAdapter. Вот код:
listview = (ListView)findViewById(R.id.listViewData);
threads = new ArrayList<HashMap<String,Object>>();
HashMap<String, Object> hm;
hm = new HashMap<String, Object>();
hm.put(TNAME, "Привет,");
hm.put(TTEXT, "\"ХэшКод\"!");
hm.put(IMG, ImageManager.downloadImage("http://hashcode.ru/upfiles/logo.png"));
threads.add(hm);
SimpleAdapter adapter = new SimpleAdapter(this,
threads, R.layout.list, new String[]{TNAME,TTEXT,IMG}, new int[]{R.id.text1,R.id.text2,R.id.img});
listview.setAdapter(adapter);
Метод downloadImage:
public static Bitmap downloadImage(String iUrl) {
Bitmap bitmap = null;
HttpURLConnection conn = null;
BufferedInputStream buf_stream = null;
try {
Log.v(TAG, "Starting loading image by URL: " + iUrl);
conn = (HttpURLConnection) new URL(iUrl).openConnection();
conn.setDoInput(true);
conn.setRequestProperty("Connection", "Keep-Alive");
conn.connect();
buf_stream = new BufferedInputStream(conn.getInputStream(), 8192);
bitmap = BitmapFactory.decodeStream(buf_stream);
buf_stream.close();
conn.disconnect();
buf_stream = null;
conn = null;
} catch (MalformedURLException ex) {
Log.e(TAG, "Url parsing was failed: " + iUrl);
} catch (IOException ex) {
Log.d(TAG, iUrl + " does not exists");
} catch (OutOfMemoryError e) {
Log.w(TAG, "Out of memory!!!");
return null;
} finally {
if ( buf_stream != null )
try { buf_stream.close(); } catch (IOException ex) {}
if ( conn != null )
conn.disconnect();
}
return bitmap;
}
Всё работает, но изображение не появляется, в logcat при этом пишется, "resolveUri failed on bad bitmap uri: android.graphics.Bitmap@NUMBER"