1. Download our Official Android App: Forums for Android!

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

Discussion in 'Android Development' started by spy0401, Jun 16, 2011.

  1. spy0401

    spy0401 Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    4
    Joined:
    Jun 16, 2011

    Jun 16, 2011
    4
    0
    5
    my code&#65306;

    Code (Text):
    1.  
    2. String img_1 = "<img src='http://l.yimg.com/f/i/tw/monday/hp/110616_18.jpg' />";
    3. String img_2 = "<img src='http://l.yimg.com/f/i/tw/monday/hp/110616_17.jpg' />";
    4.  
    5. ArrayList<HashMap<String,Object>> ListItem = new ArrayList<HashMap<String,Object>>();
    6.  
    7. HashMap<String,Object> oHash;
    8. oHash= new HashMap<String, Object>();
    9. oHash.put("item", Html.fromHtml(img_1,ig,null));
    10. ListItem.add(oHash);
    11.  
    12. oHash = new HashMap<String,Object>();
    13. oHash.put("item", Html.fromHtml(img_2,ig,null));
    14. ListItem.add(oHash);
    15.  
    16. SimpleAdapter adapter = new SimpleAdapter(this,
    17.        ListItem,
    18.        R.layout.main_menu_row,
    19.        new String[]{"item"},
    20.        new int[]{R.id.main_menu_textview});
    21.  
    22. lv.setAdapter(adapter);
    23.  
    Result&#65306;
    [​IMG]

    why not can show HTML Image ?

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

    why this mode can's ?
    :(

    ImageGetter Code&#65306;
    Code (Text):
    1.  
    2. ImageGetter ig = new ImageGetter(){
    3.  public Drawable getDrawable(String source) {
    4.   try{
    5.    Drawable d = Drawable.createFromStream(new URL(source).openStream(), "src name");
    6.    d.setBounds(0, 0, d.getIntrinsicWidth(),d.getIntrinsicHeight());
    7.    return d;
    8.   }catch(IOException e){
    9.    Log.v("IOException",e.getMessage());
    10.    return null;
    11.   }
    12.  }
    13. };
    14.  
     

    Advertisement

  2. rwagnes

    rwagnes Newbie
    Rank:
    None
    Points:
    36
    Posts:
    28
    Joined:
    Jun 4, 2011

    Can you please provide the xml for R.layout.main_menu_row? Thanks!
     
  3. spy0401

    spy0401 Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    4
    Joined:
    Jun 16, 2011

    Jun 16, 2011
    4
    0
    5
    Hi R.layout.main_menu_row content&#65306;

    Code (Text):
    1.  
    2. <?xml version="1.0" encoding="utf-8"?>
    3. <LinearLayout
    4.   xmlns:android="[URL]http://schemas.android.com/apk/res/android[/URL]"
    5.   android:orientation="vertical"
    6.   android:layout_width="match_parent"
    7.   android:layout_height="match_parent">
    8.     <TextView
    9.      android:text="TextView"
    10.      android:id="@+id/main_menu_textview"
    11.      android:layout_height="wrap_content"
    12.      android:padding="10dip"
    13.      android:layout_gravity="center"
    14.      android:gravity="center"
    15.      android:textSize="20dip"
    16.      android:layout_width="match_parent">
    17.     </TextView>
    18. </LinearLayout>
    19.  
    Thanks :)
     

Share This Page

Loading...