I want to add an image to the listview, how do i do so? The names and type are displaying properly. Currently stuck here.
.//other codes
.
.
try{
JSONArray arr = new JSONArray(res);
for(int i=0;i<arr.length();i++){
HashMap<String, String> map = new HashMap<String, String>();
JSONObject e = arr.getJSONObject(i);
map.put("placeID", ""+ e.getString("placeID"));
map.put("placeName",""+ e.getString("placeName"));
map.put("placeType", ""+ e.getString("placeType"));
map.put("image", R.drawable.ball_green);
mylist.add(map);
}
}catch(JSONException e) {
Log.e("log_tag", "Error parsing data "+e.toString());
}
ListAdapter adapter = new SimpleAdapter(this, mylist , R.layout.places,
new String[] { "placeName", "placeType" },
new int[] { R.id.placeName, R.id.placeType });
.
.
.//other codes
I want the image appropriately like:

The
R.javaclass is auto-generated at build-time and maintains a ‘list’ of integers which are resource ids. In other wordsR.<anything>is anIntegerand doesn’t directly represent the resource (string, drawable etc).As your
HashMapis expectingStringtypes for both keys and values, you’ll need to convert theball_greenresource id to aString. Example…In order to use it again you’ll have to convert that
Stringback to anIntegerwhen using it to set the image of a widget such as anImageViewetc.