Simpleadapter of the ListView
The Simpleadapter constructor is:
Public Simpleadapter (context context, list<?. extends Map<string,?>> data, int resource, string[] from, int[] To)
The context of the parameter: the contexts, such as this. The view context in which the associated Simpleadapter runs
Parameter Data:map list, list of data to be displayed, this part needs to be implemented by itself, such as the example of GetData (), the type to be consistent with the above, each item to be consistent with the specified entry from
Parameter resource:listview the ID of the individual layout file, this layout is your custom layout, and you want to show what the layout looks like in this layout. This layout must include the control ID defined in to
Parameter from: A list of each item column name that is added to the map, with the column name in the array
parameter to: is an int array, the ID of the array is the ID of the individual controls in the custom layout and needs to correspond to the from above.
The following is a code snippet, although not intended for illustration purposes, but the Simpleadapter usage is complete.
protected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.recall); Sysapplication.getinstance (). Addactivity ( This); ListView= (ListView) This. Findviewbyid (R.id.listview);Listview.setadapter (Getadapter ()); } protectedSimpleadapter Getadapter () {List<User> users =getusers (); ListNewArraylist(); for(User u:users) {HashMap<string, String> temp =NewHashmap<string, string>(); Temp.put ("Name", U.getusers_name ()); Data.add (temp); } Simpleadapter Adapter=NewSimpleadapter (Getapplicationcontext (), data, R.layout.recall_item,NewString[] {"Name" }, New int[] {r.id.name}); LOG.I ("Info", "Fill data Complete"); returnadapter; }
The corresponding: (The red font is displayed in the ListView)