I currently trying to developp an app on Android, which allow users to list their own objet in a listView.
I'm facing a problem to convert the url string of the objet image, into an imageview.
I already succeed to retrieve the object url from JSON, but once i got it , i dont know how to put it in my imageView.
This is my code :
@Override
protected String doInBackground(String... arg0) {
try {
JSONParser jParser = new JSONParser();
JSONObject json = jParser.getJSONFromUrl(yourJsonStringUrl);
dataJsonArr = json.getJSONArray("objects");
//Création de la ArrayList qui nous permettra de remplire la listView
listItem = new ArrayList<HashMap<String, String>>();
// On parcour le JSON
for (int i = 0; i < dataJsonArr.length(); i++) {
JSONObject c = dataJsonArr.getJSONObject(i);
// Formation des items de notre ListView
map = new HashMap<String, String>();
map.put("titre", c.getString("title"));
map.put("price", c.getString("price"));
map.put("addedDate", c.getString("addedDate"));
map.put("img", c.getString("picture_url"));
listItem.add(map);
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(String message) {
Bitmap bmap = getBitmapFromURL(listItem.get(0).get("img").toString());
image.setImageBitmap(bmap);
//Création d'un SimpleAdapter qui se chargera de mettre les items présent dans notre list (listItem) dans la vue fragment_add_objet
mSchedule = new SimpleAdapter (getActivity(), listItem, R.layout.layout_user_objects,
new String[] {"img", "titre", "price", "addedDate"}, new int[] {R.id.img, R.id.titre, R.id.price, R.id.addedDate});
//On attribut à notre listView l'adapter que l'on vient de créer
maListViewPerso.setAdapter(mSchedule);
}
}