Why in ViewHolder pattern should the ViewHolder class be static?

前端 未结 2 879
感动是毒
感动是毒 2021-02-07 00:46

I am just trying to have a better understanding of the following pattern I regularly use to optimize ListView

My readings only pointed me to the fact that a

2条回答
  •  攒了一身酷
    2021-02-07 01:16

    My opinion is that it is better to have the ViewHolder class static as it won't leak the Adapter.

    If the adapter retains some heavy Collections or even Views (depends on each particular case), it would be great to keep control of which objects retain the Adapter.

    Having a lot of objects instances of an inner class will have those objects referencing the Adapter, thus retaining it. You should be careful about how the tags are managed (if the views are cleaned/removed automatically there is no problem>).

提交回复
热议问题