If someone doesn't understand why Viewholder can play an optimization role,
I'll make a brief statement here:
Android's Findviewbyid action is time-consuming and requires traversing the tree structure of the layout to find the corresponding view. So if we want to optimize this piece, we need to cache the content after find, so we use the Viewholder method.
This method is easy to understand, but maybe some people are more serious, like me, this can play a role in caching, then why do internal classes have to be declared static, ordinary internal classes do not also play such an effect? This question also bothered me for a long time. Until I read "effective Java" this book, only to solve my confusion, originally this is not Android optimization, but Java advocated optimization.
"Effective Java" 22nd a static member class is preferred
One of the suggestions is:
If the declaring member class does not require access to the perimeter instance, always place the static modifier in its declaration, making it a static member class, not a non-static member class.
Because an instance of a non-static member class contains an additional reference to a perimeter object, saving the reference consumes time and space and causes the perimeter class instance to be persisted when it is eligible for garbage collection. If you need to assign an instance without a perimeter instance, you cannot use a non-static member class because an instance of a non-static member class must have a perimeter instance.
PS: Highly recommend "effective Java" this book, will let you have unexpected harvest.
Wen/cppalien (author of Jane's book)
Original link: Http://www.jianshu.com/p/aa965968cbf5
Copyright belongs to the author, please contact the author to obtain authorization, and Mark "book author".
ListView optimization Why Viewholder with Static class (reprint)