This article from http://blog.csdn.net/hellogv/
The ListView is a frequently used control, and each subkey inside the ListView item can make a string, or it can be a combined control. Let's talk about the ListView implementation:
1. Prepare the data for the ListView to be displayed;
2. Using the one-dimensional or multidimensional dynamic array to save data;
2. Build adapter , simply, < Span style= "font-size:medium;" The adapter is item array dynamic array How many items are generated by the number of elements;
3. Put Adapter add to the ListView and show it out.
Next, take a look at the ListView implemented by this article code:
Next, you start the XML code for the UI:
Main.xml code such as the following, very easy, do not need to explain more:
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout android:id= "@+id/linearlayout01" Android:layo Ut_width= "Fill_parent" android:layout_height= "fill_parent" xmlns:android= "http://schemas.android.com/apk/r Es/android "> <listview android:layout_width=" wrap_content "android:layout_height=" W Rap_content "android:id=" @+id/mylistview "> </ListView></LinearLayout>
My_listitem.xml code such as the following, My_listitem.xml is used to design the ListView item:
<?xml version=" 1.0 "encoding=" Utf-8 "? ><linearlayout android:layout_width=" F Ill_parent "xmlns:android=" http://schemas.android.com/apk/res/android "android:orientation=" vertical " android:layout_height= "Wrap_content" android:id= "@+id/mylistitem" android:paddingbottom= "3dip" android:paddingleft= "10dip" > <textview android:layout_height= "Wrap_content" a Ndroid:layout_width= "Fill_parent" android:id= "@+id/itemtitle" android:textsize= "30dip" > </TextView> <textview android:layout_height= "Wrap_content" Android : layout_width= "fill_parent" android:id= "@+id/itemtext" > </textview></linearlayout></ textarea> </span> </span>
Explain some of the properties that are used inside:
1.paddingbottom= "3dip", layout set aside 3 pixels of blank space at the bottom
2.paddingleft= "10dip", layout to left a blank area of 10 pixels
3.textsize= "30dip", TextView's font size is 30 pixels.
The last is the Java source code:
public void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.main); The ListView in the binding XML, as the container for item ListView list = (ListView) Findviewbyid (R.id.mylistview); Generate dynamic array, and reprint data arraylist<pashmap<string, string>> mylist = new arraylist<pashmap<string, string& Gt;> (); for (int i=0;i<30;i++) {hashmap<string, string> map = new hashmap<string, string> (); Map.put ("Itemtitle", "This is Title ..."); Map.put ("Itemtext", "This is Text ..."); Mylist.add (map); }//build adapter, array = = = "ListItem simpleadapter mschedule = new Simpleadapter (this,//no explanation XML implementation of mylist,//data source R.layout.my_listitem,//listitem Dynamic arrays and ListItem corresponding subkeys New string[] {"Itemtitle", "Itemtext"}, ListItem XML file Two TextView ID of the polygon in the new int[] {r.id.itemtitle,r.id.itemtext}); Added and displayed list.setadapter (Mschedule); }
Android Getting Started the sixth ListView (i)