Skip to content Skip to sidebar Skip to footer

Android Viewholder Implementation

I understand the idea and usage of Viewholder pattern, but still I have one question: Assume we have one TextView in the viewholder, and 10 items to display ('item0, item1....'). I

Solution 1:

Is there any cloning in the background?

Android preallocate a number of views that are enough to fill the screen of the device where you are running the app ( a pool of views ), identical from the content perspective but differently from the reference perspective

Solution 2:

Assuming that you implement your ViewHolder inside an adapter class and you use the holder in the getView() method, the only thing that is for sure, is that the TextView in your case , describe a slot of the parent structure (e.g. ListView). Once you have defined the slot in an xml, that is inflated from your adapter, there is no cloning or something like that. According to Google Documentation the holder idea is described as :

Your code might call findViewById() frequently during the scrolling of ListView, which can slow down performance. Even when the Adapter returns an inflated view for recycling, you still need to look up the elements and update them. A way around repeated use of findViewById() is to use the "view holder" design pattern.

A ViewHolder object stores each of the component views inside the tag field of the Layout, so you can immediately access them without the need to look them up repeatedly. First, you need to create a class to hold your exact set of views.

There is not cloning , only reusability of the view

Post a Comment for "Android Viewholder Implementation"