Implementation method of Android optimized adapter through viewholder (must see)
Definition of adapter class:
The adapter object is the bridge between the AdapterView and the underlying data. The adapter is used to access data items and is responsible for generating views for data items
AdapterView is an abstract class, which is used for views that need to fill themselves with adapters. Its common subclass is listview. When the AdapterView is displayed, the getview () method of the adapter is called to create and add a view of each sub item. The getview () method of the adapter is used to create these views. The adapter does not create a new view for each row of data, but provides a method to recycle the old view. The running mechanism is simply that when the getview () method is called, if the convertview parameter is not null, the convertview is used instead of creating a new view. The reference of each UI control is obtained through the convertview. Findviewbyid () method, and then the view is filled with the data bound to the position of the current item
For optimization, the viewholder mode is used. Viewholder is a static class that can be used to save the view of each row to avoid calling findviewbyid() every time getview is called
Model.java
ModelAdapter.java
row_ layout.xml
The above code basically realizes the function
However, it is cumbersome to customize the viewholder every time. I found a tool class on the Internet and shared it
ViewHolder.java
usage method:
The above article on the implementation method of Android through viewholder optimization adapter (must see) is all the content shared by Xiaobian. I hope it can give you a reference and support more programming tips.