Android 在多列表视图中添加图像
有人知道如何将图像添加到multi-listview中吗?我想要的是在Android 在多列表视图中添加图像,android,android-layout,android-listview,Android,Android Layout,Android Listview,有人知道如何将图像添加到multi-listview中吗?我想要的是在map1.put(“Icon”,“InsertImage”)中添加一个图像 下面的代码是我的java类 public class MultiList extends ListActivity { ListView lv; SimpleAdapter sd; @Override public void onCreate(Bundle savedInstanceState) {
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());
}
}
}
公共类多列表扩展ListActivity{
ListView lv;
SimpleDapter sd;
@凌驾
创建时的公共void(Bundle savedInstanceState){
试一试{
super.onCreate(savedInstanceState);
lv=getListView();
ArrayList alist=新的ArrayList();
HashMap1=新的HashMap();
map1.put(“类别”、“类别1”);
地图1.放置(“图标”、“插入图像”);
地图1.put(“说明”,“2轴3轮或4轮车辆,不包括出租车”);
列表.添加(map1);
sd=新的SimpleAdapter(this,alist,R.layout.row,新字符串[]{“Class”,“Icon”,“Description”},新int[]{R.id.c1,R.id.i2,R.id.d3});
低压设置适配器(sd);
}
捕获(例外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>
您需要更改映射到的数据类型。尝试HashMap
而不是HashMap
请参阅以获取更多帮助。我对它不是很了解,最后我已更改为另一种方法来显示我的信息。