Android Baseadapter GetView Understanding

Source: Internet
Author: User

A ListView is a very common control used by wirelessly.

The Android design uses adapter to manage the ListView.

However, the system-provided adapter does not meet some of the complex display conditions, and this time we need to use baseadapter from the row to implement the control of the ListView.

Other methods are very good, here is the main explanation of the GetView method.

First the ListView in the design, in order to ensure the performance of the system (after all, the mobile terminal, system resources are limited), the design is not infinite load Itemview into the.

Imagine, if there are 1000 records, do you want to create and cache 1000 Itemview objects at the same time? What if you also include large resources like pictures?

is obviously unrealistic. Therefore, the design of the Android, the following design ideas.


As shown, the system will only create one screen Itemview, depending on the screen display control calculation.

When the first itemview is completely obscured, the system moves it as the last Itemview display. This ensures that only 7 Itemview are instantiated at all times.

But obviously ITEM8 and Item1 display the content is different, at this time, we need to use GetView this method.


GetView in the Convertview, is actually the screen display of the Itemview reference. On the first screen the data shows that Convertview is empty because they all need to be recreated.

In the second screen when the first data is displayed, Convertview is not empty, but is moved down the first screen of the first item of the View object.

What we need to do now is to re-populate the new data and make sure it shows the data for the first item on the second screen.

Specific reference Links: http://www.cnblogs.com/xiaowenji/archive/2010/12/08/1900579.html

As for the placeholder that we often see, well, in fact he is just a common way to get an object reference without having to re-getviewbyid each time.

Simply put, it is convenient to use. In fact, you don't have to use this stuff either. It is not impossible to retrieve from Convertview every time, it is wasting code, wasting resources.


And then say GetView repeated call problems, mostly due to redraw, generally, the width and height of the prize item is set to Fill_parent, try not to use match, this will be much better.

If you need to redraw viewlist, you can use notifydatasetchanged, which is primarily the function of refreshing the interface.

Specific reference Links: http://www.cnblogs.com/kissazi2/p/3721941.html


Well, at the end of the groove, I feel Android. Many control designs are highly coupled, and even if you want to isolate variables yourself, it is very difficult.

The author wants to write a general adapter, GetView inside of the variable factor abstraction, open out, the results found that this has led to a lot of interface object generation, the feeling is not as good as a page a adapter to achieve the convenience, so it is not here caught dead. This also explains why Android does not have some good rapid development frameworks that are more generic and mature.

Copyright NOTICE: Welcome reprint, but please keep the source description

Android Baseadapter GetView Understanding

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: info-contact@alibabacloud.com 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.