我在我的andorid应用程序上阅读RSS。
在我从AsyncTask扩展的类上覆盖的onPostExecute
方法中,我读了一个XML,其中有一些数据和一个在线图像网址。
这是从url字符串中获取Drawable的代码。
public static Drawable LoadImageFromWebOperations(String url) {
try {
InputStream is = (InputStream) new URL(url).getContent();
Drawable d = Drawable.createFromStream(is, "src name");
return d;
} catch (Exception e) {
return null;
}
}
然后在asyncTask中,我在xml的每个项目for
内都有这个:
List<HashMap<String,String>> aList = new ArrayList<HashMap<String,String>>();
for (int i = 0; i < items.getLength(); i++) {
Element item = (Element) items.item(i);
String title = xPath.evaluate("title", item);
String description = xPath.evaluate("description", item);
String mediaUrl = xPath.evaluate("mediathumb", item);
HashMap<String, String> hm = new HashMap<String,String>();
hm.put("title", title);
hm.put("description", description);
hm.put("noteImage", LoadImageFromWebOperations(mediaUrl)); //HERE SOME HOW I HAVE TO CONVERT THE RESULT OF THE METHOD TO STRING TO ADD TO THE ADAPTER
aList.add(hm);
}
String[] from = { "title","description", "noteImage" };
int[] to = { R.id.title,R.id.description, R.id.noteImage };
adapter = new SimpleAdapter(getBaseContext(), aList, R.layout.listview_layout, from, to);
lv1.setAdapter(adapter);
我怎么能这样做,所以我可以通过互联网将图像添加到我的listview布局imageView项目中?