The deep learning blogger of BaseAdapter has been working for several years and used ListView and other AdapterView controls for a few years. However, some issues about Adapter have not been further explored, finally, I have time to summarize some in-depth topics about BaseAdapter. This article involves three topics: the recycling mechanism and Efficiency Improvement of the Adapter, the usage of the getItemViewType ()/getViewTypeCount () method, and notifyDatasetChanged () method. 1. the recycling mechanism and efficiency of the Adapter are improved. When Android draws an Adapter, the system first calls the getCount () method, obtains the length of the ListView based on its return value, and then calls getView () based on the length () method. If the length of the ListView exceeds the screen length, android will only draw the displayed items, and the system will recycle the hidden items. As shown in, the system only draws nine items from position: 4 to positon12. if you slide by the arrow, The position12 will be recycled, and position3. in general, the items hidden by the drag will be displayed to trigger the recycling. In the getView (int position, View convertView, ViewGroup parent) method, the second parameter convertView indicates the View recently recycled by the system. If the screen displays nine items, when the control with ListView is opened for the first time, the value of convertView is null when getVIew is called because the View with ListView is not recycled, otherwise, it will not be null, but a reference to the recently recycled View. the rational use of convertView will be the key to improving the efficiency of the Adapter. Otherwise, a large amount of new View overhead will be generated. Copy code 1 @ Override 2 public View getView (int position, View convertView, ViewGroup parent) 3 {4 Holder1 holder1 = null; 5 if (null = convertView) 6 {7 System. out. println ("convertView = null" + "position:" + position); 8 holder1 = new Holder1 (); 9 convertView = LayoutInflater. from (mContext ). inflate (R. layout. textview, null); 10 holder1.textView = (TextView) convertView. findViewById (R. id. textview); 11 conver TView. setTag (holder1); 12} 13 else 14 {15 holder1 = (Holder1) convertView. getTag (); 16 System. out. println ("reuse:" + holder1.textView. getText (); 17} 18 holder1.textView. setText ("position:" + position); 19 return convertView; 20} 21 22 class Holder1 23 {24 public TextView textView; 25} copy the example in the Code Description section, drag by the arrow to display the position = 4 Item. When the system calls the getView method, the value of the second convertView parameter will be the reference of the View with position = 12 (View of the recently recycled Item ). [readers can ConvertView uses a TextView to record the position value of each View. This rule can be found.] exquisite logic Description: there is a rule when the system draws the View of an Item and recycles the View of an Item: this Item triggers the painting only when it is displayed a little bit, but it must be completely hidden before the collection is triggered. Note This description if the result is not correct during the test.