33 import android.widget.TextView; |
33 import android.widget.TextView; |
34 |
34 |
35 |
35 |
36 public class TextImageAdapter extends SimpleAdapter { |
36 public class TextImageAdapter extends SimpleAdapter { |
37 |
37 |
38 private Context context; |
38 private Context context; |
39 private ArrayList<Map<String, ?>> data; |
39 private ArrayList<Map<String, ?>> data; |
40 |
|
41 public TextImageAdapter(Context _context, ArrayList<Map<String, ?>> _data, int resource, String[] from, int[] to) { |
|
42 super(_context, _data, resource, from, to); |
|
43 context = _context; |
|
44 data = _data; |
|
45 } |
|
46 |
|
47 public static TextImageAdapter createAdapter(Context c, String[] txt, String[] img, String[] from, int[] to){ |
|
48 if(txt.length != img.length) throw new IllegalArgumentException("txt and img parameters not equal"); |
|
49 |
|
50 ArrayList<Map<String, ?>> data = new ArrayList<Map<String, ?>>(txt.length); |
|
51 |
|
52 for(int i = 0; i < txt.length; i++){ |
|
53 HashMap<String, Object> map = new HashMap<String, Object>(); |
|
54 map.put("txt", txt[i]); |
|
55 map.put("img", BitmapFactory.decodeFile(img[i])); |
|
56 data.add(map); |
|
57 } |
|
58 return new TextImageAdapter(c, data, R.layout.spinner_textimg_entry, from, to); |
|
59 } |
|
60 |
40 |
61 public View getView(int position, View convertView, ViewGroup parent){ |
41 public TextImageAdapter(Context _context, ArrayList<Map<String, ?>> _data, int resource, String[] from, int[] to) { |
62 if(convertView == null){ |
42 super(_context, _data, resource, from, to); |
63 LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
43 context = _context; |
64 convertView = inflater.inflate(R.layout.spinner_textimg_entry, parent); |
44 data = _data; |
65 } |
45 } |
66 TextView tv = (TextView) convertView.findViewById(R.id.spinner_txt); |
46 |
67 ImageView img = (ImageView) convertView.findViewById(R.id.spinner_img); |
47 public static TextImageAdapter createAdapter(Context c, String[] txt, String[] img, String[] from, int[] to){ |
68 |
48 if(txt.length != img.length) throw new IllegalArgumentException("txt and img parameters not equal"); |
69 tv.setText((String)data.get(position).get("txt")); |
49 |
70 img.setImageBitmap((Bitmap)data.get(position).get("img")); |
50 ArrayList<Map<String, ?>> data = new ArrayList<Map<String, ?>>(txt.length); |
71 |
51 |
72 return convertView; |
52 for(int i = 0; i < txt.length; i++){ |
73 } |
53 HashMap<String, Object> map = new HashMap<String, Object>(); |
|
54 map.put("txt", txt[i]); |
|
55 map.put("img", BitmapFactory.decodeFile(img[i])); |
|
56 data.add(map); |
|
57 } |
|
58 return new TextImageAdapter(c, data, R.layout.spinner_textimg_entry, from, to); |
|
59 } |
|
60 |
|
61 public View getView(int position, View convertView, ViewGroup parent){ |
|
62 if(convertView == null){ |
|
63 LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
|
64 convertView = inflater.inflate(R.layout.spinner_textimg_entry, parent); |
|
65 } |
|
66 TextView tv = (TextView) convertView.findViewById(R.id.spinner_txt); |
|
67 ImageView img = (ImageView) convertView.findViewById(R.id.spinner_img); |
|
68 |
|
69 tv.setText((String)data.get(position).get("txt")); |
|
70 img.setImageBitmap((Bitmap)data.get(position).get("img")); |
|
71 |
|
72 return convertView; |
|
73 } |
74 } |
74 } |