将Drawable转换为String,以传递给ListView布局

时间:2015-09-13 23:38:25

标签: java android xml listview android-asynctask

我在我的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项目中?

0 个答案:

没有答案