Created
December 11, 2012 20:38
-
-
Save twaddington/4261943 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Instances of this class can be used to safely retain references to | |
* <code>View</code> objects. | |
* | |
* <p> | |
* Prior to Android 4.0 storing a <code>View</code> as a tag with the | |
* {@link View#setTag(int, Object)} method could <a | |
* href="http://code.google.com/p/android/issues/detail?id=18273">result in | |
* memory leaks</a>. Instead, the {@link View#setTag(Object)} method should be | |
* used with a <code>ViewHolder</code> instance as the object. | |
* </p> | |
* | |
* @author Tristan Waddington | |
*/ | |
public class ViewHolder { | |
private SparseArray<View> mViewHolder; | |
public ViewHolder() { | |
mViewHolder = new SparseArray<View>(); | |
} | |
public void setView(int id, View view) { | |
mViewHolder.put(id, view); | |
} | |
public View getView(int id) { | |
return mViewHolder.get(id); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment