在多列表视图中添加图像

时间:2013-07-30 17:52:38

标签: android android-layout android-listview

有谁知道如何将图像添加到多列表视图中?我想要的是将图像添加到map1.put("Icon", "InsertImage");

下面的代码是我的java类

public class MultiList extends ListActivity {

    ListView lv; 
    SimpleAdapter sd;
      @Override
      public void onCreate(Bundle savedInstanceState) {
        try {
        super.onCreate(savedInstanceState);
        lv=getListView();
        ArrayList<HashMap<String,String>> alist=new ArrayList<HashMap<String,String>>();

        HashMap<String, String>map1 = new HashMap<String, String>();       
        map1.put("Class","Class 1");        
        map1.put("Icon", "InsertImage");     
        map1.put("Description", "Vehicles with 2 axles and 3 or 4 wheels excluding taxis");  
        alist.add(map1);

        sd=new SimpleAdapter(this,alist,R.layout.row,new String[]{"Class","Icon","Description"},new int[]{R.id.c1,R.id.i2,R.id.d3});
        lv.setAdapter(sd);
        }
        catch (Exception e) {
            Log.w("Sravan", e.toString());
        }
    }
}

在我的xml中:

<?xml version="1.0" encoding="UTF-8"?>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:paddingTop="4dip"
    android:paddingBottom="6dip"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <TextView
        android:id="@+id/c1"
        android:layout_width="70dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:layout_weight="0.44"
        android:text="text1"
        android:textSize="18sp" />

     <TextView
         android:id="@+id/i2"
         android:layout_width="70dp"
         android:layout_height="wrap_content"
         android:layout_marginTop="20dp"
         android:layout_weight="0.7"
         android:text="text2"
         android:textSize="16sp" />

      <TextView
          android:id="@+id/d3"
          android:layout_width="70dp"
          android:layout_height="wrap_content"
          android:layout_marginTop="20dp"
          android:layout_weight="0.7"
          android:text="text3"
          android:textSize="16sp" />

 </TableRow>

1 个答案:

答案 0 :(得分:0)

您需要更改映射到的内容的数据类型。而不是HashMap<String, String>尝试HashMap<String, Object>

有关更多帮助,请参阅this question