Extension Baseadapter can be customized for each list item, please see the following code for details:
Baseadapter_list Layout file:
<span style= "FONT-SIZE:18PX;" ><?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 " android:o rientation= "vertical" > <listview android:id= "@+id/lv_baseadapter" android:layout_width= "fill _parent " android:layout_height=" wrap_content "> </ListView></LinearLayout></span>
Baseadapter Layout file:
<span style= "FONT-SIZE:18PX;" ><?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 "> <LinearLayout Android:id= "@+id/ll_top" android:layout_height= "wrap_content" android:layout_width= "Fill_parent" a ndroid:orientation= "Horizontal" > <imageview android:id= "@+id/iv_image" android:layout_height= "wrap _content "android:layout_width=" wrap_content "android:scaletype=" Fitxy "android:src=" @drawable/a5i " android:layout_gravity= "center"/> <linearlayout android:id= "@+id/ll_right" Android:layout_wi Dth= "Fill_parent" android:layout_height= "wrap_content" android:orientation= "vertical" android:layout_ margintop= "4DP" > <textview android:id= "@+id/tv_title" android:layout_height= "Wrap_cont ENT "android:layout_width=" Wrap_content "android:textsize=" 20SP "android:text=" as "/> <textview android:id= "@+id/tv_des" android:layout_height= "Wrap_content" Android : layout_width= "wrap_content" android:textsize= "13SP" android:text= "as"/> </line Arlayout></linearlayout></relativelayout></span>
Baseadaptertest Main file:
<span style= "FONT-SIZE:18PX;" >public class Baseadaptertest extends Activity {int[] images = new int[] {r.drawable.a5i, r.drawable.a5j, R.drawable.a 5k}; String[] titles = new string[] {"Phone", "QQ", "Contact"}; string[] des = new string[] {"Currently no phone record", "currently no QQ chat record", "Recently no Contact"};p rivate ListView lv_baseadapter; @Overrideprotected void O Ncreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.baseadapter_list) ; Initview (); SetDate ();} private void Initview () {//Register control lv_baseadapter= (ListView) Findviewbyid (r.id.lv_baseadapter);//Register Click event Lv_ Baseadapter.setonitemclicklistener (New Onitemclicklistener () {@Overridepublic void Onitemclick (adapterview<? > Parent, View view,int position, long id) {Toast.maketext (Baseadaptertest.this, "clicked" +position+ ", toast.length_ Short). Show ();}}); private void SetDate () {//Bind adapter Lv_baseadapter.setadapter (baseadapter);} Baseadapter baseadapter=new Baseadapter () {/* * Returns the list item component in the postion section * @see android.widget.adapter#getview (int, AndroId.view.View, Android.view.ViewGroup) */@Overridepublic view GetView (int position, view Convertview, ViewGroup parent) { Viewholder viewholder=new Viewholder (); if (Null==convertview) {Layoutinflater Layoutinflater=layoutinflater.from ( Baseadaptertest.this); Convertview=layoutinflater.inflate (r.layout.baseadapter, null); Viewholder.iv_image= ( ImageView) Convertview.findviewbyid (r.id.iv_image); viewholder.tv_title= (TextView) Convertview.findviewbyid ( R.id.tv_title); viewholder.tv_desc= (TextView) Convertview.findviewbyid (r.id.tv_des);/* * bind current View and Viewholder */ Convertview.settag (Viewholder);} else{/* * To call the Gettag () method for a view that has already been bound, the current view does not have to be redrawn, * reduces memory resources. */viewholder= (Viewholder) Convertview.gettag ();} ViewHolder.iv_image.setImageResource (Images[position]); ViewHolder.tv_title.setText (Titles[position]); ViewHolder.tv_desc.setText (Des[position]); return convertview;} /* * Returns the ID of the list item at Postion * @see android.widget.adapter#getitemid (int) */@Overridepublic long getitemid (int position) { return position;} /* * Return to POThe contents of the list item at stion. This method calls the * @see android.widget.adapter#getitem (int) */@Overridepublic Object getItem (int position) {return position in Event listener ;} /* * Returns how many list items the Adapter will contain * @see android.widget.adapter#getcount () */@Overridepublic int getcount () {return Titles.length;}}; Private class Viewholder{imageview Iv_image; TextView Tv_title; TextView Tv_desc;}} </span>
Reprint Please specify the Source: http://blog.csdn.net/hai_qing_xu_kong/article/details/42400261 Emotional Control _
Learn about Android Baseadapter use (14)