0
佈局:Android的自定義列表SimpleAdapter - 選擇行圖標
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@android:color/black">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:id="@+id/icon"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView android:id="@+id/line_a"
android:textSize="14dp"
android:textColor="@android:color/white"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textStyle="bold"/>
<TextView android:id="@+id/line_b"
android:textSize="10dp"
android:textColor="@android:color/darker_gray"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
的Java:
SimpleAdapter sa;
ArrayList<HashMap<String,String>> list = new ArrayList<HashMap<String,String>>();
HashMap<String,String> item;
for(int i = 0; i < j; i++){
item = new HashMap<String,String>();
item.put("line1", ListData[i][0]);
item.put("line2", ListData[i][1]);
item.put("type", ListData[i][2]);
list.add(item);
}
sa = new SimpleAdapter(this, list,
R.layout.two_lines_list,
new String[] { "line1","line2" },
new int[] {R.id.line_a, R.id.line_b});
// can you add the setImageView here? If yes, how?
setListAdapter(sa);
}
我怎樣才能使該圖標擺脫RES圖像/ drawable ...取決於類型(ListData [i] [2]插入到HashMap中)?例如。如果類型爲「1」,則在第2行起始處設置icon1.png