I'm creating a ListView that contains two TextViews and an ImageView.
I'm passing data to my SimpleAdapter using a Hashmap, so I convert the ids of the images to a string and then later in the SimpleAdapter I convert them back to integers to set the image resource.
However that doesn't seem to work.
The relevant code is:
The oncreate of my activity
clubImages = new Integer[] {
R.drawable.pic1, R.drawable.pic2,
R.drawable.pic3, R.drawable.pic4,
R.drawable.pic5
};
ListView lv = (ListView)findViewById(android.R.id.list);
// create the grid item mapping
String[] from = new String[] {"image"};
int[] to = new int[] {R.id.club_image};
// prepare the list of all records
List<HashMap<String, String>> fillMaps = new ArrayList<HashMap<String, String>>();
for(int i = 0; i < eventTitles.length; i++){
HashMap<String, String> map = new HashMap<String, String>();
map.put("image", getString(clubImages[i]));
fillMaps.add(map);
}
// fill in the grid_item layout
SimpleAdapter adapter = new MySimpleAdapter(this, fillMaps, R.layout.eventview_row, from, to);
lv.setAdapter(adapter);
the simpleadapter class
public class MySimpleAdapter extends SimpleAdapter {
private List<HashMap<String, String>> results;
public MySimpleAdapter(Context context, List<HashMap<String, String>> data, int resource, String[] from, int[] to) {
super(context, data, resource, from, to);
this.results = data;
}
public View getView(int position, View view, ViewGroup parent){
Typeface type = Typeface.createFromAsset(getAssets(), "fonts/aircruiser.ttf");
View v = view;
if (v == null) {
LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.eventview_row, null);
}
mClubImageImageView = (ImageView) v.findViewById(R.id.club_image);
int ClubImageHelper = Integer.parseInt(results.get(position).get("image").toString());
mClubImageImageView.setImageResource(ClubImageHelper);
return v;
}
}
The error in my logcat
E/AndroidRuntime(19406): java.lang.NumberFormatException: unable to parse 'res/drawable-hdpi/pic1.png' as integer