1, in learning to use the ListView when the adapter adapter, the definition of myadapter need to inherit the ListAdapter interface, the interface many methods are not implemented, in order to facilitate the Google engineers to achieve a Baseadapter class, We can inherit this abstract class when we use it, so we just need to complete a few abstract methods.
public class Db_adapter extends Baseadapter {private Context context;private List <Person> personlist;public db_adapter (Context context,list<person> personlist) {this.context=context; This.personlist=personlist;} public void Setpersonlist (list<person> personlist) {this.personlist=personlist;} @Overridepublic int GetCount () {//TODO auto-generated method Stubreturn personlist.size ();} @Overridepublic Object getItem (int position) {//TODO auto-generated method Stubreturn null;} @Overridepublic long Getitemid (int position) {//TODO auto-generated method Stubreturn 0;} @Overridepublic view GetView (int position, view Convertview, ViewGroup parent) {//TODO auto-generated method Stubtextview Text=new TextView (context), Text.settext (Personlist.get (position). GetName ());//textview text2=new TextView (context );//text2.settext (Personlist.get (position) Getmoney () + ""); return text;//return null;}}
2, one of the most critical is to complete the GetView () method, the number of times the GetView method call is not the return value of the GetCount method, when there are too many entries in the ListView, here the Android virtual opportunity automatically calculates the high-end H1 of the ListView control, It then calculates the height of the TextView H2, so the H1/h2 GetView () method is called from the beginning, and when we drag up and down, we call GetView () when we don't see the first entry, even if the previous entry is not seen in the down-drag process. Then the GetView () method is still called when the callback occurs again.
Android Learning notes for the ListView and adapter adapters