Skip to content

Instantly share code, notes, and snippets.

@indrek-koue
Created January 3, 2013 23:27
Show Gist options
  • Save indrek-koue/4448498 to your computer and use it in GitHub Desktop.
Save indrek-koue/4448498 to your computer and use it in GitHub Desktop.
BaseAdapter broilerplate for android adapters
import android.content.Context;
import android.view.LayoutInflater;
import android.widget.BaseAdapter;
import java.util.List;
public abstract class MyBaseAdapter<T> extends BaseAdapter {
private List<T> mList;
private LayoutInflater mInflater;
private Context mContext;
public MyBaseAdapter(Context con, List<T> list) {
setInflater(LayoutInflater.from(con));
setList(list);
setContext(con);
}
@Override
public int getCount() {
return getList().size();
}
@Override
public Object getItem(int position) {
return getList().get(position);
}
@Override
public long getItemId(int position) {
return position;
}
public LayoutInflater getInflater() {
return mInflater;
}
public void setInflater(LayoutInflater inflater) {
this.mInflater = inflater;
}
public List<T> getList() {
return mList;
}
public void setList(List<T> mList) {
this.mList = mList;
}
public Context getContext() {
return mContext;
}
public void setContext(Context mContext) {
this.mContext = mContext;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment