If you think the Android project ponyville-live-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package com.ponyvillelive.app.ui;
/*fromwww.java2s.com*/import android.content.Context;
import android.view.LayoutInflater;
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. */publicabstractclass BindableAdapter<T> extends BaseAdapter {
privatefinal Context context;
privatefinal LayoutInflater inflater;
public BindableAdapter(Context context) {
this.context = context;
this.inflater = LayoutInflater.from(context);
}
public Context getContext() {
return context;
}
@Override publicabstract T getItem(int position);
@Override publicfinal View getView(int position, View view, ViewGroup container) {
if (view == null) {
view = newView(inflater, position, container);
if (view == null) {
thrownew IllegalStateException("newView result must not be null.");
}
}
bindView(getItem(position), position, view);
return view;
}
/** Create a new instance of a view for the specified position. */publicabstract View newView(LayoutInflater inflater, int position, ViewGroup container);
/** Bind the data for the specified {@code position} to the view. */publicabstractvoid bindView(T item, int position, View view);
@Override publicfinal View getDropDownView(int position, View view, ViewGroup container) {
if (view == null) {
view = newDropDownView(inflater, position, container);
if (view == null) {
thrownew IllegalStateException("newDropDownView result must not be null.");
}
}
bindDropDownView(getItem(position), position, view);
return view;
}
/** Create a new instance of a drop-down view for the specified position. */public View newDropDownView(LayoutInflater inflater, int position, ViewGroup container) {
return newView(inflater, position, container);
}
/** Bind the data for the specified {@code position} to the drop-down view. */publicvoid bindDropDownView(T item, int position, View view) {
bindView(item, position, view);
}
}