Android Development most common examples of finishing----(2) Customizing the ListView (Simpleadapter Implementation)
First, Activity
Mainactivity.java Source:
public class Mainactivity extends Activity {@Overrideprotected void onCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main);//step1string[] Contentarray = new String[]{"Content 1", "Content 2 "," Content 3 "," Content 4 "," Content 5 "}; ListView LV = (ListView) Findviewbyid (r.id.lv);//step2arraylist
Second, XML layout file
(1) Mainactivity the layout of the main interface source code activity_main.xml:
<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android" android:layout_width= "Match_ Parent " android:layout_height=" match_parent " android:orientation=" vertical "> <listview Android:id= "@+id/lv" android:layout_width= "match_parent" android:layout_height= "Wrap_content"/></ Linearlayout>
(1) The layout of the ListView List Unit source code list_item.xml:<?xml version= "1.0" encoding= "Utf-8"?> <linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "android:layout_height=" 60DP "android:gravity=" center_vertical "android:layout_width=" Match_parent " android:orientation= "Horizontal" > <linearlayout android:layout_width= "0DP" Android:layout_heigh t= "Match_parent" android:layout_weight= "2" android:gravity= "center_vertical" android:orientation= "vertical" > &L T TextView android:id= "@+id/starttimetext" android:layout_height= "Wrap_content" Android:layout_w Idth= "Match_parent" android:text= "22:00"/> <textview android:id= "@+id/endtimetext" android:layout_height= "Wrap_content" android:layout_width= "match_parent" android:text= "23:00"/> </LinearLa yout> <imageview android:id= "@+id/separator" android:layout_weight= "1" android:layout_width= "0DP" and roid:layout_height= "Wrap_content"/> < TextView android:id= "@+id/content" android:layout_width= "0DP" android:layout_height= "Wrap_content" Android:layo ut_weight= "/> </LinearLayout>"
Iii. Related ResourcesFiles under res/drawable-mdpi/:
Separator.png
Four, the effect
Android Development most common examples of finishing----(2) Customizing the ListView (Simpleadapter Implementation)