Create a ListView using Simpleadapter
Program Listing 1
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "Android:layout_width=" Match_parent "android:layout_height=" match_parent "> <listview android:la Yout_width= "Fill_parent" android:layout_height= "wrap_content" android:id= "@+id/mylist"/></Line Arlayout>
Program Listing 2
package xiaocool.net.classspace.classblog;import android.os.bundle;import android.support.v7.app.actionbaractivity;import android.widget.listview;import android.widget.simpleadapter;import java.util.arraylist;import java.util.hashmap;import Java.util.list;import java.util.map;import xiaocool.net.classspace.r;/** * created by mryu on 2015/3/14. */public class tuijian extends actionbaractivity { private listview listview; private string [] contents=new string[]{] What's the use of yelling at kids? "What's the use of yelling at a child?" "What's the use of yelling at a child?" "}; private string[] times=new string[]{" 2015/3/14 14:44 "," 2015/3/ 14 14:44 "," 2015/3/14 14:44 "}; private int[] images=new int[]{ r.drawable.touxiang,r.drawable.touxiang,r.drawable.touxiang}; @Override &Nbsp; protected void oncreate (bundle savedinstancestate) { super.oncreate (savedinstancestate); setcontentview (R.layout.classblog_tuijian); //Create a list collection The elements of the ,list collection are map list<map<string,object>> Listitems=new arraylist<map<string, object>> (); for (int i=0;i<contents.length;i++) { Map<String,Object> listitem=new HashMap<String,Object> (); listitem.put ("Content", Contents[i]); listitem.put ("Time", Times[i]); &nbsP; listitem.put ("image", Images[i]); listitems.add (ListItem); } //Create a simpleadapter Simpleadapter simpleadapter =new simpleadapter (this,listitems,r.layout.tuijian_item, new string[]{" Content "," Time "," image "}, new int[]{R.id.textContent,R.id.textTime,R.id.imageView3} ); listview= (ListView) This.findviewbyid (r.id.mylist); Listview.setadapter (Simpleadapter); }}
Program Listing 3 Each list item can be customized to your needs
<?xml version= "1.0" encoding= "Utf-8"? ><relativelayout xmlns:android= "http// Schemas.android.com/apk/res/android " android:layout_width=" Match_parent " android: layout_height= "match_parent" android:orientation= "Horizontal" > <textview android:layout_width= " Wrap_content " android:layout_height=" Wrap_content " android:text= "New text" android:id= "@+id/textcontent" android:textsize= "20SP" android:layout_marginleft= "55DP" android:layout_marginstart= "55DP" android: Layout_alignparentleft= "true" android:layout_alignparentstart= "true" /> <textview android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" android:text= "New text" android:id= "@+id /texttime " android:textsize=" 15SP " android:layout_alignbottom= "@+id/imageview3" android:layout_alignleft= "@+id/textcontent" android: Layout_alignstart= "@+id/textcontent" /> <ImageView android:layout_width= "Wrap_content" Android:layout_height= "Wrap_conTent " android:id=" @+id/imageview3 " android:src= "@drawable/touxiang" Android:layout_alignparenttop= "true" android:layout_ Alignparentright= "true" android:layout_alignparentend= "true" android:layout_marginright= "50DP" android:layout_marginend= "50DP" /> <TextView android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" android: text= "New text" android:id= "@+id/textZan" android:layout_alignbottom= "@+id/imageview3" android:layout_torightof= "@+id/ Textcontent " android:layout_toendof=" @+id/textContent " / ></RelativeLayout>
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/5B/41/wKioL1UD5VPx_z8OAAFHvTWthys168.jpg "title=" Qq20150314153137.png "alt=" Wkiol1ud5vpx_z8oaafhvtwthys168.jpg "/>
This article is from the "Ahu-on-the-road" blog, be sure to keep this source http://xiaocool.blog.51cto.com/1593956/1620353
The use of Android learning--listview (iii)