我需要从包含图像网址的字符串中创建一个新的Image实例。
例如:http://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png
这些类型的URL来自JSON解析器,我想使用它们填充多按钮列表的图标。
我使用此Model类的getItemAt方法将数据放入多按钮列表中。每个多按钮都有一个图标和一些行。我已将Line1命名为name,将Line2命名为rating。 我想通过字符串URL制作一个Image,以便我可以更改multibutton图标以替换h.put("icon", defaultIcon)行中的defaultIcon。
static class Model implements ListModel {
public Object getItemAt(int index) {
Hashtable h = new Hashtable();
Hashtable entry = (Hashtable) results.elementAt(index);
String name = (String) entry.get("name");
Double rating = (Double) entry.get("rating");
String url = (String) entry.get("icon");
h.put("name", name);
h.put("icon", defaultIcon); // change defaultIcon with an Image from url String
if (rating == null) {
h.put("rating", "Not rated");
} else {
h.put("rating", "Rating: " + rating.toString());
}
return h;
}