Skip to content

Instantly share code, notes, and snippets.

@ruben-h
Last active August 29, 2015 14:21
Show Gist options
  • Save ruben-h/6b63588e3d7093732a6d to your computer and use it in GitHub Desktop.
Save ruben-h/6b63588e3d7093732a6d to your computer and use it in GitHub Desktop.
CountryListArrayAdapter before Butterknife
public class CountryListArrayAdapter extends ArrayAdapter<CountrycodeActivity.Country> {
private final List<CountrycodeActivity.Country> list;
private final Activity context;
static class ViewHolder {
protected TextView name;
protected ImageView flag;
}
public CountryListArrayAdapter(Activity context,
List<CountrycodeActivity.Country> list) {
super(context, R.layout.activity_countrycode_row, list);
this.context = context;
this.list = list;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = null;
if (convertView == null) {
LayoutInflater inflator = context.getLayoutInflater();
view = inflator.inflate(R.layout.activity_countrycode_row, null);
final ViewHolder viewHolder = new ViewHolder();
viewHolder.name = (TextView) view.findViewById(R.id.name);
viewHolder.flag = (ImageView) view.findViewById(R.id.flag);
view.setTag(viewHolder);
} else {
view = convertView;
}
ViewHolder holder = (ViewHolder) view.getTag();
holder.name.setText(list.get(position).getName());
holder.flag.setImageDrawable(list.get(position).getFlag());
return view;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment