public class ViewHolder {
private SparseArray<View> viewHolder;
private View view;
public static ViewHolder getViewHolder(View view){
ViewHolder viewHolder = (ViewHolder) view.getTag();
if (viewHolder == null) {
viewHolder = new ViewHolder(view);
view.setTag(viewHolder);
}
return viewHolder;
}
private ViewHolder(View view) {
this.view = view;
viewHolder = new SparseArray<View>();
view.setTag(viewHolder);
}
public <T extends View> T get(int id) {
View childView = viewHolder.get(id);
if (childView == null) {
childView = view.findViewById(id);
viewHolder.put(id, childView);
}
return (T) childView;
}
欢迎使用CSDN-markdown编辑器
最新推荐文章于 2021-01-07 23:01:28 发布