java - Android custom List SimpleAdapter - chose row icon -
layout:
<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 = 0; < 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 add setimageview here? if yes, how? setlistadapter( sa ); }
how can make icon image res/drawable... depending on type (listdata[i][2] inserted in hashmap)? eg. if type "1" set icon1.png @ beginning of 2-line-row
you should override simpleadapter.getview(int position, view convertview, viewgroup parent)
method, , list item current position(the first param in method), check value set set icon want.
note: you' d better use viewholder pattern in getview
method performance.
Comments
Post a Comment