5
我想在ListView中顯示新聞(來自RSS)。我已經成功創建我的ListView,正確顯示標題和說明。但是我無法顯示來自網址的圖片。在ListView中顯示來自url的可繪製圖像
這裏是我的代碼:
maListViewPerso = (ListView) findViewById(R.id.listviewperso);
ArrayList <HashMap<String, String>> listItem = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map;
int i = 0;
while (i < 55)
{
map = new HashMap<String, String>();
map.put("titre", newsArray[i]);
map.put("description", newsArray[i+1]));
map.put("img", newsArray[i+4]);
listItem.add(map);
i += 5;
}
SimpleAdapter mSchedule = new SimpleAdapter (this.getBaseContext(), listItem,
R.layout.affichageitem, new String[] {"img", "titre", "description"},
new int[] {R.id.img, R.id.titre, R.id.description});
maListViewPerso.setAdapter(mSchedule);
正如您可以猜到,newsArray[i+4]
包含我的圖像的URL。
我寫了一個函數drawable_from_url
,它返回一個android.graphics.drawable.Drawable
,它工作正常。我試圖寫這個:
map.put("img", String.valueOf(drawable_from_url(newsArray[i+4], "newsPic")));
但它不工作(無圖像顯示)。的 String.valueOf(drawable_from_url(newsArray[i+4], "newsPic"))
價值的一個例子是
[email protected]
任何想法?
謝謝。