I’m working on a project. That could populate list through json. I’ve parse the data from http://10.0.2.2/mobile_version/get_supplier_pro_list.php, and it is displaying me the text but not image, what i’ve done is
// Hashmap for ListView
ArrayList<HashMap<String, String>> contactList = new ArrayList<HashMap<String, String>>();
// Creating JSON Parser instance
JSONParser jParser = new JSONParser();
// getting JSON string from URL
JSONObject json = jParser.getJSONFromUrl(url);
try {
// Getting Array of Contacts
sup_pd_list = json.getJSONArray(TAG_SUPPLIERS);
// looping through All Contacts
for (int i = 0; i < sup_pd_list.length(); i++) {
JSONObject c = sup_pd_list.getJSONObject(i);
// Storing each json item in variable
String suply_id = c.getString(TAG_ID);
String pd_name = c.getString(TAG_PRO_NAME);
String pd_price = c.getString(TAG_PRO_PRICE);
String pd_thumbnail = c.getString(TAG_PRO_THUMBNAIL);
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
// adding each child node to HashMap key => value
map.put(TAG_ID, suply_id);
map.put(TAG_PRO_NAME, pd_name);
map.put(TAG_PRO_PRICE, pd_price);
map.put(TAG_PRO_THUMBNAIL, pd_thumbnail);
// adding HashList to ArrayList
contactList.add(map);
}
} catch (JSONException e) {
e.printStackTrace();
}
/**
* Updating parsed JSON data into ListView
* */
ListAdapter adapter = new SimpleAdapter(this, contactList,
R.layout.single_list_item, new String[] { TAG_PRO_NAME,
TAG_PRO_PRICE, TAG_PRO_THUMBNAIL}, new int[] {
R.id.pd_name, R.id.pd_price , R.id.pd_thumbnail });
setListAdapter(adapter);
}
and in logcat, it shows me
12-14 03:47:12.743: I/System.out(314): resolveUri failed on bad bitmap uri: fceacd5431438f9d93fb4f885a3b2990.png
12-14 03:47:12.762: I/System.out(314): resolveUri failed on bad bitmap uri: d254d82762217f8e1005013c8926f53e.jpg
And through parsing, what i get is
{"suppliers":[{"suply_id":null,"pd_name":"car","pd_price":"200000.00","pd_thumbnail":"fceacd5431438f9d93fb4f885a3b2990.png"}],"success":1}
Help needed. Thanks in advance.
A couple of things need to happen in order to display the image. First, you need to change your HashMap to
HashMap<String, Object>()to accept a drawable object.Next, you need to get the drawable object from your string name by doing something like this:
Here is a tutorial that you can use to derive things from minus the string to drawable conversion
http://www.androidpractice.com/2012/01/static-listview-with-images-in-android.html
Finally, I’m not sure if
R.layout.single_list_itemis the right type of list item for this, but I may be mistaken, so please don’t quote me on that one.