• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps use ListView & HashMap<String,Object> can not show HTML Image tag .... why?

spy0401

Lurker
my code&#65306;

Code:
String img_1 = "<img src='http://l.yimg.com/f/i/tw/monday/hp/110616_18.jpg' />";
String img_2 = "<img src='http://l.yimg.com/f/i/tw/monday/hp/110616_17.jpg' />";
 
ArrayList<HashMap<String,Object>> ListItem = new ArrayList<HashMap<String,Object>>();
 
HashMap<String,Object> oHash;
oHash= new HashMap<String, Object>();
oHash.put("item", Html.fromHtml(img_1,ig,null));
ListItem.add(oHash);
 
oHash = new HashMap<String,Object>();
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});
 
lv.setAdapter(adapter);

Result&#65306;
250451_226024804093157_100000569173000_876989_1105526_n.jpg


why not can show HTML Image ?

This a way can&#65306;
Code:
String img_1 = "<img src='http://l.yimg.com/f/i/tw/monday/hp/110616_18.jpg' />";
String img_2 = "<img src='http://l.yimg.com/f/i/tw/monday/hp/110616_17.jpg' />";
 
Object[] img = new Object[]{Html.fromHtml(img_1,ig,null),Html.fromHtml(img_2,ig,null)};
 
lv.setAdapter(new ArrayAdapter<Object>(this, R.layout.main_menu_row, R.id.main_menu_textview, img));

Result&#65306;
254049_226024814093156_100000569173000_876990_5274596_n.jpg


why this mode can's ?
:(

ImageGetter Code&#65306;
Code:
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;
  }
 }
};
 
Can you please provide the xml for R.layout.main_menu_row? Thanks!

Hi R.layout.main_menu_row content&#65306;

Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="[URL]http://schemas.android.com/apk/res/android[/URL]"
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="match_parent">
    <TextView 
     android:text="TextView" 
     android:id="@+id/main_menu_textview" 
     android:layout_height="wrap_content" 
     android:padding="10dip" 
     android:layout_gravity="center" 
     android:gravity="center"
     android:textSize="20dip" 
     android:layout_width="match_parent">
    </TextView>
</LinearLayout>

Thanks :)
 
Back
Top Bottom