Page Layout<? 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:orientation= "Horizontal" >
<imageviewandroid:id= "@+id/img"android:layout_width= "80DP"android:layout_height= "80DP"android:layout_margin= "5px"/>
<linearlayoutandroid:layout_width= "Match_parent"android:layout_height= "Match_parent"android:orientation= "vertical" >
<textviewandroid:id= "@+id/title"android:layout_width= "Wrap_content"android:layout_height= "Wrap_content"android:textcolor= "#000000"android:textsize= "100px"/>
<textviewandroid:id= "@+id/info"android:layout_width= "Wrap_content"android:layout_height= "Wrap_content"android:textcolor= "#000000"android:textsize= "60px"/>
</LinearLayout></LinearLayout>
display data on a layout with Simpleadapter
Package Com.eson.simpleadapter;
import android.app.ListActivity;import Android.os.Bundle;import Android.widget.SimpleAdapter;
import java.util.ArrayList;import Java.util.HashMap;import java.util.List;import Java.util.Map;
Public class Mainactivity extends Listactivity {
@Overrideprotected void OnCreate (Bundle savedinstancestate) {super. OnCreate (savedinstancestate);simpleadapter simpleadapter = new Simpleadapter (this, GetData (), R.layout. Content_main,new string[]{"title", "Info", "IMG"}, new int []{r.id. title, r.id. Info, R.id. img});Setlistadapter (simpleadapter);
}
Private list<map<string,object>> getData () {list<map<string, object>> List = new arraylist<map<string, object>> ();map<string, object> Map = new hashmap<string, object> ();map.put ("title", "Clock");map.put ("info", "My clock on the My Phone");map.put ("img", r.drawable. i1);list.add (map);
map = new hashmap<string, object> ();map.put ("title", "Earth");map.put ("info", "This is a map of the Earth");map.put ("img", r.drawable. i2);list.add (map);
map = new hashmap<string, object> ();map.put ("title", "Go");map.put ("info", "This is a Go drawble");map.put ("img", r.drawable. i3);list.add (map);
map = new hashmap<string, object> ();map.put ("title", "Talk");map.put ("info", "This was a talk drawble");map.put ("img", r.drawable. I4);list.add (map);
map = new hashmap<string, object> ();map.put ("title", "Bird");map.put ("info", "This is a bird drawble");map.put ("img", r.drawable. i5);list.add (map);
map = new hashmap<string, object> ();map.put ("title", "Note");map.put ("info", "This is a note drawble");map.put ("img", r.drawable. I6);list.add (map);
return list; }}the Simpleadapter has five parameters, of which the following four parameters are critical. > second parameter: The parameter should be a collection object of type List<?extends map<string,?>> that generates a list item for each Map<string,?> object in the collection. > Third parameter: This parameter specifies an interface layout ID. For example, R.layout.content_main is specified here, which means that the/res/layout/content_main.xml file is used as the list component. > Fourth parameter: The parameter should be a string[] type parameter that determines the value of the key corresponding to the extract Map<string,?> object to generate the list item. > Fifth parameter: The parameter is a int[] type parameter that determines which components are populated.
Simpleadapter Use Cases