-
-
Save rocel/b3fd352bded2a92bb621 to your computer and use it in GitHub Desktop.
This file contains 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.manuelpeinado; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.widget.BaseAdapter; | |
/** | |
* A variation on Jake Wharton's BindingAdapter (https://gist.github.com/JakeWharton/5423616) which is slightly more convenient | |
* for adapters that only have one view type | |
*/ | |
public abstract class SimpleBindingAdapter<ViewClass extends View> extends BaseAdapter { | |
@SuppressWarnings("unchecked") | |
@Override | |
public final ViewClass getView(int position, View convertView, ViewGroup parent) { | |
if (convertView == null) { | |
convertView = newView(parent); | |
} | |
bindView(position, (ViewClass)convertView); | |
return (ViewClass)convertView; | |
} | |
/** Create a new instance of a view */ | |
public abstract ViewClass newView(ViewGroup parent); | |
/** Bind the data for the specified {@code position} to the {@code view}. */ | |
public abstract void bindView(int position, ViewClass view); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment