Skip to content

Instantly share code, notes, and snippets.

@SelvinPL
Last active August 29, 2015 14:24
Show Gist options
  • Select an option

  • Save SelvinPL/bb4f8aebb129f1db9420 to your computer and use it in GitHub Desktop.

Select an option

Save SelvinPL/bb4f8aebb129f1db9420 to your computer and use it in GitHub Desktop.
public class MinimalArrayAdapter<T> extends BaseAdapter {
LayoutInflater inflater = null;
ArrayList<T> mObjects = null;
public MinimalArrayAdapter(Context ctx, ArrayList<T> list) {
mObjects = list;
inflater = LayoutInflater.from(ctx);
}
@Override
public int getCount() {
return mObjects.size();
}
@Override
public T getItem(int position) {
return mObjects.get(position);
}
@Override
public long getItemId(int position) {
return position; //or ((T)getItem(position)).getId(); if we had ... but then you should also override hasStableIds
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView == null)
convertView = inflater.inflate(android.R.layout.simple_list_item_1, parent, false);
T item = getItem(position); // why getItem not direct access ... if you add filtering someday you shouldn't wory about this ...
/* setup view based on item*/
return convertView;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment