Skip to content

Instantly share code, notes, and snippets.

@maiatoday
Created September 15, 2015 08:07
Show Gist options
  • Save maiatoday/c585f08a7f4037a0c714 to your computer and use it in GitHub Desktop.
Save maiatoday/c585f08a7f4037a0c714 to your computer and use it in GitHub Desktop.
class ArrayMapAdapter extends BaseAdapter {
private final ArrayMap<String, String> mData;
public ArrayMapAdapter(ArrayMap<String, String> map) {
mData = map;
}
@Override
public int getCount() {
return mData.size();
}
@Override
public Pair<String, String> getItem(int position) {
return new Pair<>(mData.keyAt(position), mData.valueAt(position));
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final View result;
if (convertView == null) {
result = LayoutInflater.from(parent.getContext()).inflate(android.R.layout.simple_list_item_1, parent, false);
} else {
result = convertView;
}
final String value = getItem(position).second;
((TextView) result.findViewById(android.R.id.text1)).setText(value);
return result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment