Skip to content

Instantly share code, notes, and snippets.

@boloutaredoubeni
Last active January 29, 2016 16:37
Show Gist options
  • Select an option

  • Save boloutaredoubeni/51c682db44ad38d11137 to your computer and use it in GitHub Desktop.

Select an option

Save boloutaredoubeni/51c682db44ad38d11137 to your computer and use it in GitHub Desktop.
Custom Adapter Example
import ...;
public class MyCustomArrayAdapter extends ArrayAdapter<T> {
final ArrayList<T> mArrayList;
public MyCustomAdapter(Context context, ArrayList<T> list) {
super(context, -1);
mArrayList = list;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
T myItem = mArrayList.get(position);
Context context = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.id.my_row_layout_item, parent, false);
SomeChildView childView = (SomeChildView) view.findViewById(R.id.my_child_view);
childView.setSomethingInViewTo(myItem.getSomeAttribute());
return view;
}
@Override
public int getCount() {
return mArrayList.size();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment