請教 ListView 顯示 HTML Img 標籤的問題
請教各位先進,小弟我在一個範例程式中要使用 ListView 來呈現一些資料,這些資料裡面有包含 HTML 語法,例如 這是粗體、http://xxx.xxx.xxx/abc.jpg /> 這類的語法。
我目前遇到的問題是,我將這些資料,放到 HashMap
先寫好處理 HTML IMG 標籤的 ImageGetter 物件函式
ImageGetter ig = new ImageGetter(){
public Drawable getDrawable(String source) {
try{
Drawable d = Drawable.createFromStream(new URL(source).openStream(), "src name");
d.setBounds(0, 0, d.getIntrinsicWidth(),d.getIntrinsicHeight());
return d;
}catch(IOException e){
Log.v("IOException",e.getMessage());
return null;
}
}
};
以及 HTML 語法內容:
String img_1 = "http://l.yimg.com/f/i/tw/monday/hp/110616_18.jpg' />";
String img_2 = "http://l.yimg.com/f/i/tw/monday/hp/110616_17.jpg' />";
試驗一:
ArrayList
HashMap
oHash= new HashMap
oHash.put("item", Html.fromHtml(img_1,ig,null));
ListItem.add(oHash);
oHash = new HashMap
oHash.put("item", Html.fromHtml(img_2,ig,null));
ListItem.add(oHash);
SimpleAdapter adapter = new SimpleAdapter(this,
ListItem,
R.layout.main_menu_row,
new String[]{"item"},
new int[]{R.id.main_menu_textview});
objListView.setAdapter(adapter);
試驗二:
Object[] img = new Object[]{Html.fromHtml(img_1,ig,null),Html.fromHtml(img_2,ig,null)};
objListView.setAdapter(new ArrayAdapter
以上兩種測試,只有試驗二可以顯示出圖片,試驗一就不行,所以想問問是不是將資料放入 HashMap 的關係?還是其它因素?
有請板上的前輩們協助~ 謝謝