Simpleadapter is the best extensibility adapter that can define the various layouts you want.
Construction Method:
Simpleadapter (context context, list<? extends Map<string,?>> data, int resource, string[] from, int[ ] to)
The context of the parameter: the contexts, such as this. The view context in which the associated Simpleadapter runs
Parameter Data:map list, list of data to be displayed, this part needs to be implemented by itself, the type is consistent with the above, each item should be consistent with the entry specified in the From
Parameter resource:listview the ID of the individual layout file, this layout is your custom layout, and you want to show what the layout looks like in this layout. This layout must include the control ID defined in to
Parameter from: A list of each item column name that is added to the map, with the column name in the array
parameter to: is an int array, the ID of the array is the ID of the individual controls in the custom layout and needs to correspond to the from above
First Look at:
1 <Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"2 Android:layout_width= "Match_parent"3 Android:layout_height= "Match_parent" >4 5 <ListView6 Android:id= "@+id/lv"7 Android:layout_width= "Wrap_content"8 Android:layout_height= "Wrap_content" />9 Ten </Relativelayout>
Activity_main.xml
1 <Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"2 Android:layout_width= "Match_parent"3 Android:layout_height= "Match_parent" >4 5 <ImageView6 Android:id= "@+id/left_img"7 Android:layout_width= "Wrap_content"8 Android:layout_height= "Wrap_content"9 android:src= "@drawable/img01" />Ten One <TextView A Android:id= "@+id/title" - Android:layout_width= "Wrap_content" - Android:layout_height= "Wrap_content" the Android:layout_marginleft= "20DP" - Android:layout_margintop= "10DP" - Android:layout_torightof= "@id/left_img" - Android:text= "Lock Phone" + android:textsize= "24SP" /> - + <ImageView A Android:id= "@+id/right_img" at Android:layout_width= "Wrap_content" - Android:layout_height= "Wrap_content" - Android:layout_alignparentright= "true" - Android:layout_alignparenttop= "true" - android:src= "@drawable/ic_launcher" /> - <TextView in Android:id= "@+id/content" - Android:layout_below= "@id/left_img" to Android:layout_width= "Match_parent" + Android:layout_margintop= "10DP" - Android:layout_height= "Wrap_content" the Android:singleline= "true" * Android:text= "Introduction key point technology male and female students are just computer technology is to solve"/> $ Panax Notoginseng </Relativelayout>
Item_layout
1 Public classMainactivityextendsActivity {2 3 ListView LV;4 5 //Data Source6 int[] Leftimgs ={r.drawable.img01, r.drawable.img02, r.drawable.img03,7 r.drawable.img04, R.drawable.img05, r.drawable.img06,};8String[] titles = {"Lock phone", "mobile antivirus", "Unlock Phone", "Mobile internet", "My Documents", "mobile navigation" };9 intRightimgs =R.drawable.ic_launcher;Ten OneString content = "specifically dealing with locking phone-related functions, I am using the construction method of the Guardian God is the computer technology of the triangle muscle extract of the world's top count"; A - @Override - protected voidonCreate (Bundle savedinstancestate) { the Super. OnCreate (savedinstancestate); - Setcontentview (r.layout.activity_main); - -LV =(ListView) Findviewbyid (r.id.lv); + -listNewArraylist(); + for(inti = 0; I < 6; i++) { A athashmap<string, object> map =NewHashmap<string, object>(); -Map.put ("Leftimg", Leftimgs[i]); -Map.put ("title", Titles[i]); -Map.put ("Rightimg", Rightimgs); -Map.put ("Content", content); - in data.add (map); - } to +Simpleadapter adapter =NewSimpleadapter (mainactivity. This, data, -R.layout.item_phone,NewString[] {"Leftimg", "title", the"Rightimg", "content"},New int[] {r.id.left_img, * R.id.title, r.id.right_img, r.id.content}); $ Panax Notoginseng Lv.setadapter (adapter); - } the +}Mainactivity.java
Android Simpleadapter ListView (lock phone, unlock phone list)