Skip to content

Instantly share code, notes, and snippets.

@antslava
Forked from JakeWharton/BindingAdapter.java
Created April 21, 2013 21:25
Show Gist options
  • Save antslava/5431129 to your computer and use it in GitHub Desktop.
Save antslava/5431129 to your computer and use it in GitHub Desktop.
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
/** An implementation of {@link BaseAdapter} which uses the new/bind pattern for its views. */
public abstract class BindingAdapter extends BaseAdapter {
@Override public final View getView(int position, View convertView, ViewGroup parent) {
int type = getItemViewType(position);
if (convertView == null) {
convertView = newView(type, parent);
}
bindView(position, type, convertView);
return convertView;
}
/** Create a new instance of a view for the specified {@code type}. */
public abstract View newView(int type, ViewGroup parent);
/** Bind the data for the specified {@code position} to the {@code view}. */
public abstract void bindView(int position, int type, View view);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment