public class Personadapter extends
Baseadapter{
Private List persons;//The data to bind to
The ID of an entry interface for the private int resource;//binding, in this case the Item.xml
Private Layoutinflater inflater;//layout filler, which can use an XML file to generate a view object that can be used to get instance objects through the context
Public Personadapter (context context, List persons, int resource) {
Inflater = (layoutinflater) context.getsystemservice (Context.layout_inflater_service);
This.resource = resource;
this.persons = persons;
}
@Override
public int GetCount () {//Get total number of data to bind
return Persons.size ();
}
@Override
public object GetItem (int position) {//Given index value, object corresponding to index value
return Persons.get (position);
}
@Override
public long getitemid (int position) {//Get Entry ID
return position;
}
The
//ListView has caching, and when the first page is displayed, a Page object is created, and the first page is reused when the second page is displayed.
//Get Entry interface: Position the index value of the data to bind for the current entry in the collection
@Override
public View getview (int position, View Convertview, ViewGroup parent) {
TextView Nameview = null;
textview phoneview = null;
textview amountview = null;
if (Convertview = = null) {//Convertview is empty when the first page is displayed
convertview = Inflater.inflate (resource, null);//Generate 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 person = persons.get (position);
Implementing 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;
}
}