Skip to content

Instantly share code, notes, and snippets.

@niusounds
Created December 11, 2013 06:43
Show Gist options
  • Save niusounds/7906005 to your computer and use it in GitHub Desktop.
Save niusounds/7906005 to your computer and use it in GitHub Desktop.
Listを使う抽象ListAdapter
import java.util.List;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
public abstract class AbstractListAdapter<T, V extends View> extends BaseAdapter {
private List<T> list = Collections.emptyList();
@Override
public int getCount() {
return list.size();
}
@Override
public T getItem(int position) {
return list.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@SuppressWarnings("unchecked")
@Override
public View getView(int position, View convertView, ViewGroup parent) {
V view = convertView == null ? createView() : (V) convertView;
T item = getItem(position);
if (item != null) {
bind(view, item, position);
}
return view;
}
protected abstract V createView();
protected abstract void bind(V view, T item, int position);
public List<T> getList() {
return list;
}
public void setList(List<T> list) {
this.list = list;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment