Skip to content

Instantly share code, notes, and snippets.

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