0
嘿我試圖添加圖標到我的ListView。 這是如何看起來我的ListAdapter。Android ListView自定義圖標
ListAdapter adapter = new SimpleAdapter(this, menuItems,R.layout.list_item,
new String[] { KEY_NAME, Icon }, new int[] {R.id.name, R.id.icon});
setListAdapter(adapter);
這就是我如何得到我的圖標
String imgFilePath = ASSETS_DIR + ICON_NAME;
try {
Bitmap bitmap = BitmapFactory.decodeStream(this.getResources().getAssets()
.open(imgFilePath));
Icon.setImageBitmap(bitmap);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
我應該如何將圖標添加到我的ListView?我試圖在互聯網上使用一些例子,但它看起來像ListAdaptar和ArrayList是完全不同的方式。
我的列表項xml文件。
<ImageView
android:id="@+id/myicon"
android:layout_gravity="left"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#dc6800"
android:textSize="16sp"
android:textStyle="bold"
android:paddingTop="6dip"
android:paddingBottom="2dip" />
每個列表項目的圖標是否不同? –