why does the ViewHolder pattern work?

前端 未结 3 754
逝去的感伤
逝去的感伤 2020-12-10 09:50

I learned Android\'s ArrayAdapter today, and find there is a commom pattern which uses a ViewHolder to hold Views\' reference instead of calling findViewById everytime.

3条回答
  •  攒了一身酷
    2020-12-10 10:09

    Sorry but denis' answer may be wrong. In fact, the view instances(and ViewHolders) are as many as your screen can display.

    If your screen looks like:

    [list view]
    the first item
    the second item
    the third item
    the fourth item
    

    You will have 4 instances of views. If you scroll screen, the first will disappear but be pass to getItem() as convertView for you to create the fifth item.

    So you can use the references in first ViewHolder.

提交回复
热议问题