CopyCode The Code is as follows: public class personadapter extends
Baseadapter {
Private list persons; // data to be bound
Private int resource; // the ID of the bound entry interface. In this example, It is item. xml.
Private layoutinflater Inflater; // layout filler, which can generate a view object using an XML file and obtain instance objects through context
Public personadapter (context, list persons, int Resource ){
Inflater = (layoutinflater) Context. getsystemservice (context. layout_inflater_service );
This. Resource = resource;
This. Persons = Persons;
}
@ Override
Public int getcount () {// get the total number of data to be bound
Return persons. Size ();
}
@ Override
Public object getitem (INT position) {// specify the index value to obtain the object corresponding to the index value
Return persons. Get (position );
}
@ Override
Public long getitemid (INT position) {// get the entry ID
Return position;
}
// Listview has the cache function. When the first page is displayed, the page object is created. When the second page is displayed, the created object on the first page is reused.
// Entry acquisition page: Position indicates the index value of the data to be bound to the current entry in the set.
@ Override
Public View getview (INT position, view convertview, viewgroup parent ){
Textview nameview = NULL;
Textview phoneview = NULL;
Textview amountview = NULL;
If (convertview = NULL) {// when the first page is displayed, convertview is empty.
Convertview = Inflater. Inflate (resource, null); // generate an entry object
Nameview = (textview) convertview. findviewbyid (R. Id. Name );
Phoneview = (textview) convertview. findviewbyid (R. Id. Phone );
Amountview = (textview) convertview. findviewbyid (R. Id. amount );
Viewcache cache = new viewcache ();
Cache. amountview = amountview;
Cache. nameview = nameview;
Cache. phoneview = phoneview;
Convertview. settag (cache );
} Else {
Viewcache cache = (viewcache) convertview. gettag ();
Amountview = cache. amountview;
Nameview = cache. nameview;
Phoneview = cache. phoneview;
}
Person = Persons. Get (position );
// Implement data binding
Nameview. settext (person. getname ());
Phoneview. settext (person. getphone ());
Amountview. settext (person. getamount ());
Return convertview;
}
Private final class viewcache {
Public textview nameview;
Public textview phoneview;
Public textview amountview;
}
}