Last active
December 16, 2015 11:09
-
-
Save ManuelPeinado/5424997 to your computer and use it in GitHub Desktop.
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
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