Back to project page Android-MyStarterApp.
The source code is released under:
Apache License
If you think the Android project Android-MyStarterApp listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package co.kaush.mystarterapp.app.ui.adapters; /*from www . j av a 2 s . c o m*/ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import co.kaush.mystarterapp.app.ui.viewholder.ViewHolder; import co.kaush.mystarterapp.app.R; /** * an adapter that takes advantage of: * * 1. reusableView (convertView) caching from the Android framework * 2. ViewHolder pattern which caches view holders (and prevents multiple costly findViewByID calls) * * @param <T> */ public abstract class ReuseCachedViewAdapter<T> extends BaseAdapter { public static final int ITEM_VIEW_TYPE_1 = 0; public static final int ITEM_VIEW_TYPE_2 = 1; @Override public abstract T getItem(int position); @Override public final View getView(int position, View reusableView, ViewGroup container) { if (reusableView == null) { // isSameViewType reusableView = newView(LayoutInflater.from(container.getContext()), position, container); reusableView.setTag(R.id.KEY_VIEWHOLDER_TYPE, ITEM_VIEW_TYPE_1); reusableView.setTag(R.id.KEY_VIEWHOLDER, getNewViewHolder()); } ViewHolder vh = (ViewHolder<T>) reusableView.getTag(R.id.KEY_VIEWHOLDER); vh.bind(getItem(position)); return vh.getView(); } public abstract View newView(LayoutInflater layoutInflater, int position, ViewGroup container); public abstract ViewHolder<T> getNewViewHolder(); private boolean _isSameViewType() { return true; } }