Last active
August 29, 2015 14:21
-
-
Save ruben-h/fa7f7ca0d9afc43d0a18 to your computer and use it in GitHub Desktop.
CountryListArrayAdapter with Butterknife
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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