Use Baseadapter first to rewrite the four methods inside:
public int GetCount ()
The number of items in your item, which is the column count of the ListView you need to show. Typically returns a container's size () directly
Public Object getItem (int position)
returns the data for each item
public long getitemid (int position)
returns the ID of each item, typically returned directly to position
Public View GetView (int position, view Convertview, ViewGroup parent)
The most important is: redraw the view, the number of calls is determined by the first method. Finally, the view is returned.
The parameter inside the position is the current item's Id,convertview is the layout of the current item.
Note: Some controls must be set to no profit focus with a click.
Cache processing:
If the ListView is too long when you need to reload the control each time it is wasted memory, you need to do cache processing, usually by writing an inner class Viewholder used to store the already loaded controls.
public class personadapter extends baseadapter { private list<person> persons; private context context; public personadapter (List<person> persons, context context) { super (); this.persons = persons; this.context = context; } @Override public int getcount () { return persons.size (); } @Override public object getitem (int position) { return persons.get (position); } @Override public long getitemid (int position) { return position; } @Override public view getview (int position, view convertview, Viewgroup parent) { ViewHolder holder; if (convertview == null) { holder = new viewholder (); /** * Get layouts */ convertview = view.inflate (context, r.laYout.avtivity_item, null); // Find Controls holder.name = by holder ( TextView) convertview.findviewbyid (r.id.item_textview_name); holder.age = (TextView) convertview.findviewbyid (r.id.item_ Textview_age); holder.button = (Button) convertview.findviewbyid (R.id.item_button); //setting tag Convertview.settag (Holder); } else { holder = (Viewholder) Convertview.gettag (); } //Setting spatial Properties holder.name.settext (Persons.get (position). GetName ()); holder.age.settext ("" +persons.get (position). Getage ()); return convertview; } class viewholder { public TextView name; public textview age; public button button; }}
About the use of Baseadapter in the ListView