anto2b Posted December 26, 2011 Share Posted December 26, 2011 Bonjour à tous, Je crée une application qui recupère les données de chaque article. Pour cela j'utilise le JSON, pour parser mes données qui se trouvent à cette adresse : http://bastia1905.co...ort_android.php Mon problème est le suivant : Lorsque je fais cette instruction : map.put("thumb", "Thumb : " + e.getString("thumb"));[/color] [color=#1F1F1F] cela me renvoie une adresse url d'une image. Mais je n'arrive pas à l'afficher dans un imageView. Auriez-vous une solution à mon problème ? Merci de votre aide. Voici mon activité : package com.pxr.tutorial.json;[/font][/color] [color=#1F1F1F][font=TrebuchetMS,]import java.util.ArrayList; import java.util.HashMap;[/font][/color] [color=#1F1F1F][font=TrebuchetMS,]import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import com.pxr.tutorial.xmltest.R; import android.app.ListActivity; import android.content.Intent; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ListAdapter; import android.widget.ListView; import android.widget.SimpleAdapter;[/font][/color] [color=#1F1F1F][font=TrebuchetMS,]public class AttualitaActivity extends ListActivity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.attualita); ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>(); JSONObject json = JSONfunctions.getJSONfromURL("http://bastia1905.com/android/export_android.php"); try{ JSONArray earthquakes = json.getJSONArray("articles"); for(int i=0;i<earthquakes.length();i++){ HashMap<String, String> map = new HashMap<String, String>(); JSONObject e = earthquakes.getJSONObject(i); map.put("id", String.valueOf(i)); map.put("titre", e.getString("titre")); map.put("extrait", e.getString("extrait")); map.put("thumb", "Thumb : " + e.getString("thumb")); map.put("date", e.getString("date")); mylist.add(map); } }catch(JSONException e) { Log.e("log_tag", "Error parsing data "+e.toString()); } ListAdapter adapter = new SimpleAdapter(this, mylist , R.layout.listplaceholder, new String[] { "titre", "extrait", "thumb", "date"}, new int[] { R.id.item_title, R.id.item_subtitle, R.id.item_thumb, R.id.item_date}); setListAdapter(adapter); final ListView lv = getListView(); lv.setTextFilterEnabled(true); lv.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { @SuppressWarnings("unchecked") HashMap<String, String> o = (HashMap<String, String>) lv.getItemAtPosition(position); Intent affichearticle = new Intent(getApplicationContext(),ArticleActivity.class); affichearticle.putExtra("titre", o.get("titre")); // On appelle l'activity startActivity(affichearticle); } }); } }[/font][/color] [color=#1F1F1F][font=TrebuchetMS,] Link to comment Share on other sites More sharing options...
nbbu Posted December 28, 2011 Share Posted December 28, 2011 Il te faut récupérer l'image à partir de l'URL et ensuite l'affectée à ton imageview. A la lecture de ton code j'imagine que tu t'es inspiré de ça : http://stackoverflow...-simple-adapter (je dis ça à cause de ta variable earthquakes :P ), le gars fait appel à LoadImageFromWebOperations Tu peux t'inspirer de ce tutoriel pour comprendre comment faire. http://mickael-lt.de...erie-connectee/ public void setImage(ImageView aView, URL aURL) Link to comment Share on other sites More sharing options...
anto2b Posted December 28, 2011 Author Share Posted December 28, 2011 Mon problème est résolu, merci de votre aide. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.