Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ArrayAdapterWithIcon extends ArrayAdapter<String> {
- private List<Integer> _icons;
- public ArrayAdapterWithIcon(Context context, String[] items, Integer[] images)
- {
- super(context, android.R.layout.select_dialog_item, items);
- this._icons = Arrays.asList(images);
- }
- @NonNull
- @Override
- public View getView(int position, View convertView, ViewGroup parent)
- {
- View view = super.getView(position, convertView, parent);
- TextView textView = (TextView) view.findViewById(android.R.id.text1);
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
- textView.setCompoundDrawablesRelativeWithIntrinsicBounds(_icons.get(position), 0, 0, 0);
- } else {
- textView.setCompoundDrawablesWithIntrinsicBounds(_icons.get(position), 0, 0, 0);
- }
- textView.setCompoundDrawablePadding(
- (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 12, getContext().getResources().getDisplayMetrics()));
- return view;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement