Arrayadapter Adapter:
(1) for displaying basic text content
(2) Basic use Process: New Adapter---Create or load data source---Adapter load data source---View load adapter
Arrayadapter (context, the layout file that corresponds to each list item loaded by the current ListView, data Source)
(Arrayadapter) The implementation process of the data adapter:
1. Create a new adapter
Arr_adapter=new arrayadapter<string> (context, layout file, data source)
Arr_adapter=new arrayadapter<string> (Context (this), the current ListView loads each list item corresponding to the layout file (Android. r.layout.simple_list_item_1), Data source (string[]arr_data={"1", "2", "3", "4"});
2. Add a data source to the adapter (included in the previous step)
3. View (ListView) load Adapter
Listview.setadapter (Arr_adapter);
Using Simpleadapter
Private ListView ListView;
Private Simpleadapter Simple_adapter;
Declaring an adapter
Private list<map<string,object>> dataList;
Datalist=new arraylist<map<string,object>> ();
1, create a new data adapter-simpleadapter ();
2. The adapter loads the data source
Simple_adapter = new Simpleadapter (This,getdata () * Gets the data source *,r.layout. layout file name, newstring[]{"key value name 1", "Key Value Name 2"},new int[]{ R.id. Control name 1,r.id. Control Name 2});
3. View (ListView) load Adapter
Listview.setadapter (Simple_adapter);
Generate a data source
Private list<map<string, object>> GetData () {
for (int i=0;i<20;i++) {
Map<string,object> map=new hashmap<string,object> ();
Map.put ("Key value name", R.drawable.ic_launcher);
Map.put ("Key Value name", "Test text" +i);
Datalist.add (map);
}
return dataList;
}
Note: Map.put ("pic", R.drawable.ic_launcher); Map.put ("Text", "Test text" +i); here pic and text with new int[] {R.id.pic,r.id.text} Nothing (just the same name) is associated with the name in new string[] {"pic", "text"}.
The use of the "Android" two adapters