All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.devnied.emvnfccard.utils.ViewHolder Maven / Gradle / Ivy

There is a newer version: 2.1.1
Show newest version
package com.github.devnied.emvnfccard.utils;

import android.util.SparseArray;
import android.view.View;

/**
 * Class to manage View Holder pattern for list view
 */
public final class ViewHolder {

	/**
	 * Class to get and store a view in the holder
	 * 
	 * @param pView
	 *            the root view
	 * @param pId
	 *            id of view to find
	 * @return The View
	 */
	@SuppressWarnings("unchecked")
	public static  T get(final View pView, final int pId) {
		SparseArray viewHolder = (SparseArray) pView.getTag();
		if (viewHolder == null) {
			viewHolder = new SparseArray();
			pView.setTag(viewHolder);
		}
		View childView = viewHolder.get(pId);
		if (childView == null) {
			childView = pView.findViewById(pId);
			viewHolder.put(pId, childView);
		}
		return (T) childView;
	}

	/**
	 * Private constructor
	 */
	private ViewHolder() {
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy