Created
December 15, 2015 06:05
-
-
Save darkengine/e3ebec2647bb055215ed to your computer and use it in GitHub Desktop.
Generic ViewHolder
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
package com.rockyapps.dbdemo.ui; | |
import android.util.SparseArray; | |
import android.view.View; | |
/** | |
* Created by apple on 15/12/15. | |
*/ | |
public class GenericViewHolder { | |
@SuppressWarnings("unchecked") | |
public static <T extends View> T get(View view, int id) { | |
SparseArray<View> viewHolder = (SparseArray<View>) view.getTag(); | |
if (viewHolder == null) { | |
viewHolder = new SparseArray<View>(); | |
view.setTag(viewHolder); | |
} | |
View childView = viewHolder.get(id); | |
if (childView == null) { | |
childView = view.findViewById(id); | |
viewHolder.put(id, childView); | |
} | |
return (T) childView; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Android generic view holder, makes working with ListView and GridView conveniently.