Skip to content

Instantly share code, notes, and snippets.

@yakivmospan
Created December 18, 2014 20:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yakivmospan/5053a9990576cbc57832 to your computer and use it in GitHub Desktop.
Save yakivmospan/5053a9990576cbc57832 to your computer and use it in GitHub Desktop.
public class Adapter
extends BaseAdapter {
private List<Object> mData;
private LayoutInflater mInflater;
public Adapter(Context context, List<Object> data) {
mInflater = LayoutInflater.from(context);
mData = data;
}
@Override
public int getCount() {
return mData.size();
}
@Override
public Object getItem(int position) {
return this.mData.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
if (convertView == null) {
holder = new ViewHolder();
convertView = mInflater.inflate(R.layout.layoutId, parent, false);
holder.view = convertView.findViewById(R.id.viewId);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
return convertView;
}
public void setData(List<Object> data) {
mData = data;
notifyDataSetChanged();
}
public void addData(List<Object> data) {
mData.addAll(data);
notifyDataSetChanged();
}
private static class ViewHolder {
View view;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment