I want to display news (from RSS) in a ListView. I have already managed to create my ListView, correctly displaying the name and description. But I can not display the image from the URL.
Here is my code:
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);
As you can guess, it newsArray[i+4]contains the URL of my image.
I wrote a function drawable_from_urlthat returns android.graphics.drawable.Drawableand works fine. I tried to write this:
map.put("img", String.valueOf(drawable_from_url(newsArray[i+4], "newsPic")));
But it does not work (image is not displayed). An example value
String.valueOf(drawable_from_url(newsArray[i+4], "newsPic"))
might be
android.graphics.drawble.BitmapDrawable@481f16d0
Any idea?
Thank.
source
share