Created
September 15, 2015 08:07
-
-
Save maiatoday/c585f08a7f4037a0c714 to your computer and use it in GitHub Desktop.
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
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