Android Learning notes for the ListView and adapter adapters

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.