When using Listview or GridView, a custom data adapter is often required, and getView() is generally overridden. There is a convertView parameter in this method, which is the View used to load data. Simple but inefficient way for beginners
Every time you load a view, you have to recreate a lot of view objects. If a listview contains 10,000 items, this loading method will fail. Using convertView By using Android's Recycler mechanism and convertView to recycle View, the efficiency is substantially improved. Each creation of View is relatively time-consuming, so the judgment of convertView passed in by the getview method should be fully utilized.
Using ViewHolder ViewHolder encapsulates the views that need to be cached, and setTag of convertView is used to cache them for the next call. When your listview has a diversified layout, the role of viewholder is obvious, and the efficiency is improved again. The findViewById() method of View is also time-consuming, so you need to consider calling it only once, and then use the View.getTag() method to obtain the ViewHolder object.
Elegant use of ViewHolder When using ViewHolder, you have to findViewById again and again, and add the definition of View in ViewHolder again and again. When there are many views, it feels annoying. The base-adapter-helper class library seems to solve this problem perfectly. The design idea is to use SparseArray to store view references instead of the original ViewHolder, without declaring a large number of Views, which is concise and clear. I also wrote a simple version of ViewHolder myself.
It is super simple and concise to use:
|
<<: How to develop an Apple App of the Year? See what the founder of Replay said
>>: Android Wear is also about to be upgraded to 5.0, and the watch face display mode is turned on
As the year 2021 is about to pass, the new consum...
Recently, many places in Fujian, Guangdong and Gu...
After the content of Huaban.com was rectified A l...
On September 1, a drama project by a film and tel...
The essence of a private domain is to have long-t...
Reviewer of this article: Chen Haixu, Deputy Dire...
This silly bird is just as confused as the rest o...
When users across the country were staying at hom...
Welcome to the 45th issue of the Nature Trumpet c...
Affected by the epidemic, many companies are faci...
"Shi Sanxi·The Essence of Eight Mansions&quo...
In the 1970s, the Japanese government implemented...
1) Good Project III) Course Introduction 01. The ...
Copywriting with sufficient promotional power wil...
Microbial electrochemistry is an emerging field t...