IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Android Discussion :

Parser JSON problème d'image


Sujet :

Android

  1. #1
    Membre habitué
    Homme Profil pro
    Inscrit en
    Octobre 2011
    Messages
    281
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Octobre 2011
    Messages : 281
    Points : 161
    Points
    161
    Par défaut Parser JSON problème d'image
    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.com/android/export_android.php

    Mon problème est le suivant : Lorsque je fais cette instruction,

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    map.put("thumb", "Thumb : " +  e.getString("thumb"));
    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é :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    package com.pxr.tutorial.json;
     
    import java.util.ArrayList;
    import java.util.HashMap;
     
    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;
     
    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);
    			}
    		});
        }
    }

  2. #2
    Membre averti Avatar de hariman
    Homme Profil pro
    Développeur Java, Android
    Inscrit en
    Janvier 2008
    Messages
    200
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Ile Maurice

    Informations professionnelles :
    Activité : Développeur Java, Android
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Janvier 2008
    Messages : 200
    Points : 413
    Points
    413
    Par défaut
    Bonjour,

    Est-ce que l'url que tu obtient avec e.getString("thumb") est bien correct ?

    Essaye de l'afficher si tu n'en est pas sûr.
    Les boutons et adorent être cliqués, donc ne les oubliez pas

  3. #3
    Membre habitué
    Homme Profil pro
    Inscrit en
    Octobre 2011
    Messages
    281
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Octobre 2011
    Messages : 281
    Points : 161
    Points
    161
    Par défaut
    Oui j'ai essayer d'afficher le lien et cela marche. Maintenant j'aimerais afficher l'image correspondant à l'url mais je ne sais pas comment faire.

  4. #4
    Rédacteur
    Avatar de David55
    Homme Profil pro
    Ingénieur informatique
    Inscrit en
    Août 2010
    Messages
    1 542
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2010
    Messages : 1 542
    Points : 2 808
    Points
    2 808
    Par défaut
    Bonjour,

    Il est peut être possible d'envoyer un tableau de byte ou un Bitmap!!! Dans ce cas c'est assez simple je pense!

  5. #5
    Membre habitué
    Homme Profil pro
    Inscrit en
    Octobre 2011
    Messages
    281
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Octobre 2011
    Messages : 281
    Points : 161
    Points
    161
    Par défaut
    Pourriez vous me montrer comment ça marche avec mon code s'il vous plait, merci de votre aide.

  6. #6
    Rédacteur
    Avatar de David55
    Homme Profil pro
    Ingénieur informatique
    Inscrit en
    Août 2010
    Messages
    1 542
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2010
    Messages : 1 542
    Points : 2 808
    Points
    2 808
    Par défaut
    Tres bien si thumb représente l'url de l'image, il faut d'abord le télécharger!
    Pour cela,

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
     
    URL url = new URL(e.getString("thumb"));
    File file = new File("nom_image.jpg");
     
    URLConnection ucon = url.openConnection();
    InputStream is = ucon.getInputStream();
    BufferedInputStream bis = new BufferedInputStream(is);
     
    // Ceci
    ByteArrayBuffer baf = new ByteArrayBuffer(50);
                            int current = 0;
                            while ((current = bis.read()) != -1) {
                                    baf.append((byte) current);
                            }
     
    //ou ceci
    /*
    Bitmap bm = BitmapFactory.decodeStream(is);
    */
     
    is.close ();
    "baf" ou "bm" contient ton image

    Edit:
    Avec le Bitmap tu peux tout simplement faire:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    ImageView i = (ImageView) findViewById (R.id.imageView);
    i.setImageBitmap(bm);

  7. #7
    Membre habitué
    Homme Profil pro
    Inscrit en
    Octobre 2011
    Messages
    281
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Octobre 2011
    Messages : 281
    Points : 161
    Points
    161
    Par défaut
    Donc je met le code que vous m'avez proposé dans un map.put ?

  8. #8
    Rédacteur
    Avatar de David55
    Homme Profil pro
    Ingénieur informatique
    Inscrit en
    Août 2010
    Messages
    1 542
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2010
    Messages : 1 542
    Points : 2 808
    Points
    2 808
    Par défaut
    euh non désolé tu laisses ta map comme ceci! Le code sert par la suite lorsque tu récupères la valeur du thumb pour l'afficher dans ton imageView

    EDIT:
    Pour cela, il faut redéfinir un BaseAdapter! Voici à quoi ressemblera le tiens:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
     
    package com.monpackage;
     
    import java.util.List;
     
     
    import android.content.Context;
    import android.graphics.Color;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.BaseAdapter;
    import android.widget.CheckBox;
    import android.widget.TextView;
     
    public class myBaseAdapter extends BaseAdapter
    {
    	ArrayList<HashMap<String, String>> mylist;
    	LayoutInflater	inflater;
     
    	public myBaseAdapter (Context context, ArrayList<HashMap<String, String>> myList)
    	{
    		inflater = LayoutInflater.from (context);
    		this.myList = myList;
    	}
     
    	@Override
    	public int getCount ()
    	{
    		return myList.size ();
    	}
     
    	@Override
    	public Object getItem (int position)
    	{
    		return myList.get (position);
    	}
     
    	@Override
    	public long getItemId (int position)
    	{
    		// TODO Auto-generated method stub
    		return position;
    	}
     
    	@Override
    	public View getView (int position, View convertView, ViewGroup parent)
    	{
    		ViewHolder holder;
    		if (convertView == null)
    		{
    			holder = new ViewHolder ();
    			convertView = inflater.inflate (R.layout.affichageitem, null);
    			holder.titre = (TextView) convertView.findViewById (R.id.item_title);
    			holder.extrait = (TextView) convertView.findViewById (R.id.item_subtitle);
    			holder.thumb = (ImageView) convertView.findViewById (R.id.item_thumb);
    			holder.date = (TextView) convertView.findViewById (R.id.item_date);
    		}
    		else
    		{
    			holder = (ViewHolder) convertView.getTag ();
    		}
     
    		holder.titre.setText (myList.get (position).get ("titre").toString ());
    		holder.extrait.setText (myList.get (position).get ("extrait").toString ());
    		holder.date.setText (myList.get (position).get ("date").toString ());
     
    		URL url = new URL(myList.get (position).get ("thumb").toString ());
    		File file = new File("nom_image.jpg");
     
    		URLConnection ucon = url.openConnection();
    		InputStream is = ucon.getInputStream();
    		BufferedInputStream bis = new BufferedInputStream(is);
     
    		Bitmap bm = BitmapFactory.decodeStream(is);
    		holder.thumb.setImageBitmap(bm);
     
    		is.close ();
     
    		convertView.setTag (holder);
     
    		return convertView;
    	}
     
    	public class ViewHolder
    	{
    		TextView	titre;
    		TextView	extrait;
    		ImageView	thumb;
    		TextView	date;
    	}
    }

  9. #9
    Membre habitué
    Homme Profil pro
    Inscrit en
    Octobre 2011
    Messages
    281
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Octobre 2011
    Messages : 281
    Points : 161
    Points
    161
    Par défaut
    Oui mais la je n'est plus mon parser JSON ? Je dois tout recommencer donc ?

  10. #10
    Rédacteur
    Avatar de David55
    Homme Profil pro
    Ingénieur informatique
    Inscrit en
    Août 2010
    Messages
    1 542
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2010
    Messages : 1 542
    Points : 2 808
    Points
    2 808
    Par défaut
    Citation Envoyé par anto2b Voir le message
    Oui mais la je n'est plus mon parser JSON ? Je dois tout recommencer donc ?
    Euh non au lieu d'utiliser ListAdapter tu utilises la classe que je t'ai écrite dans mon post précédent!

  11. #11
    Membre habitué
    Homme Profil pro
    Inscrit en
    Octobre 2011
    Messages
    281
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Octobre 2011
    Messages : 281
    Points : 161
    Points
    161
    Par défaut
    J'ai oublier de vous précisez que j'ai aussi une classe :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    package com.pxr.tutorial.json;
     
    import java.io.BufferedReader;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import org.apache.http.HttpEntity;
    import org.apache.http.HttpResponse;
    import org.apache.http.client.HttpClient;
    import org.apache.http.client.methods.HttpPost;
    import org.apache.http.impl.client.DefaultHttpClient;
    import org.json.JSONException;
    import org.json.JSONObject;
     
    import android.util.Log;
     
    public class JSONfunctions {
     
    	public static JSONObject getJSONfromURL(String url){
    		InputStream is = null;
    		String result = "";
    		JSONObject jArray = null;
     
    		//http post
    	    try{
    	            HttpClient httpclient = new DefaultHttpClient();
    	            HttpPost httppost = new HttpPost(url);
    	            HttpResponse response = httpclient.execute(httppost);
    	            HttpEntity entity = response.getEntity();
    	            is = entity.getContent();
     
    	    }catch(Exception e){
    	            Log.e("log_tag", "Error in http connection "+e.toString());
    	    }
     
    	  //convert response to string
    	    try{
    	            BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
    	            StringBuilder sb = new StringBuilder();
    	            String line = null;
    	            while ((line = reader.readLine()) != null) {
    	                    sb.append(line + "\n");
    	            }
    	            is.close();
    	            result=sb.toString();
    	    }catch(Exception e){
    	            Log.e("log_tag", "Error converting result "+e.toString());
    	    }
     
    	    try{
     
                jArray = new JSONObject(result);            
    	    }catch(JSONException e){
    	            Log.e("log_tag", "Error parsing data "+e.toString());
    	    }
     
    	    return jArray;
    	}
    }

  12. #12
    Rédacteur
    Avatar de David55
    Homme Profil pro
    Ingénieur informatique
    Inscrit en
    Août 2010
    Messages
    1 542
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2010
    Messages : 1 542
    Points : 2 808
    Points
    2 808
    Par défaut
    Bonjour,

    Pour inclure, la classe que je t'ai passé tu peux t'inspirer de ce post!

  13. #13
    Membre habitué
    Homme Profil pro
    Inscrit en
    Octobre 2011
    Messages
    281
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Octobre 2011
    Messages : 281
    Points : 161
    Points
    161
    Par défaut
    Dans mon Adapter j'ai une erreur à la ligne qui est en gras. Il faut que je remplace eleve ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    package com.pxr.tutorial.json;
     
    import java.io.BufferedInputStream;
    import java.io.File;
    import java.io.InputStream;
    import java.net.URL;
    import java.net.URLConnection;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    import com.pxr.tutorial.xmltest.R;
    import android.content.Context;
    import android.graphics.Bitmap;
    import android.graphics.BitmapFactory;
    import android.graphics.Color;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.BaseAdapter;
    import android.widget.CheckBox;
    import android.widget.ImageView;
    import android.widget.TextView;
     
    public class myBaseAdapter extends BaseAdapter
    {
    	ArrayList<HashMap<String, String>> mylist;
    	LayoutInflater	inflater;
     
    	public myBaseAdapter (Context context, ArrayList<HashMap<String, String>> myList)
    	{
    		inflater = LayoutInflater.from (context);
    		myList.eleve = myList;
    	}
     
    	public int getCount ()
    	{
    		return myList.size ();
    	}
     
    	public Object getItem (int position)
    	{
    		return myList.get (position);
    	}
     
    	public long getItemId (int position)
    	{
    		// TODO Auto-generated method stub
    		return position;
    	}
     
    	public View getView (int position, View convertView, ViewGroup parent)
    	{
    		ViewHolder holder;
    		if (convertView == null)
    		{
    			holder = new ViewHolder ();
    			convertView = inflater.inflate (R.layout.listplaceholder, null);
    			holder.titre = (TextView) convertView.findViewById (R.id.item_title);
    			holder.extrait = (TextView) convertView.findViewById (R.id.item_subtitle);
    			//holder.thumb = (ImageView) convertView.findViewById (R.id.item_thumb);
    			holder.date = (TextView) convertView.findViewById (R.id.item_date);
    		}
    		else
    		{
    			holder = (ViewHolder) convertView.getTag ();
    		}
     
    		holder.titre.setText (myList.get (position).get ("titre").toString ());
    		holder.extrait.setText (myList.get (position).get ("extrait").toString ());
    		holder.date.setText (myList.get (position).get ("date").toString ());
     
    		URL url = new URL(myList.get (position).get ("thumb").toString ());
    		File file = new File("nom_image.jpg");
     
    		URLConnection ucon = url.openConnection();
    		InputStream is = ucon.getInputStream();
    		BufferedInputStream bis = new BufferedInputStream(is);
     
    		Bitmap bm = BitmapFactory.decodeStream(is);
    		holder.thumb.setImageBitmap(bm);
     
    		is.close ();
     
    		convertView.setTag (holder);
     
    		return convertView;
    	}
     
    	public class ViewHolder
    	{
    		TextView	titre;
    		TextView	extrait;
    		ImageView	thumb;
    		TextView	date;
    	}
    }

  14. #14
    Rédacteur
    Avatar de David55
    Homme Profil pro
    Ingénieur informatique
    Inscrit en
    Août 2010
    Messages
    1 542
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2010
    Messages : 1 542
    Points : 2 808
    Points
    2 808
    Par défaut
    Oui désolé c'est un erratum de ma part!

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    this.myList = myList;

  15. #15
    Membre habitué
    Homme Profil pro
    Inscrit en
    Octobre 2011
    Messages
    281
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Octobre 2011
    Messages : 281
    Points : 161
    Points
    161
    Par défaut
    Merci. Maintenant j'ai declarer un nouvelle adapter dans mon activity (voir tesxte gras rouge). Mon problème je ne vois pas quel est le 2e parametre dans (à la place des ...) :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    adapter = new myBaseAdapter (this, .... );
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    package com.pxr.tutorial.json;
    
    import java.util.ArrayList;
    import java.util.HashMap;
    
    import org.json.JSONArray;
    import org.json.JSONException;
    import org.json.JSONObject;
    import com.pxr.tutorial.xmltest.R;
    import android.app.ListActivity;
    import android.os.Bundle;
    import android.util.Log;
    
    public class AttualitaActivity extends ListActivity {
        /** Called when the activity is first created. */
       
        
        private myBaseAdapter adapter = null;
        
        @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());
            }
            
    
            adapter = new myBaseAdapter (this);
    		setListAdapter (adapter);
        }
    }

  16. #16
    Rédacteur
    Avatar de David55
    Homme Profil pro
    Ingénieur informatique
    Inscrit en
    Août 2010
    Messages
    1 542
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2010
    Messages : 1 542
    Points : 2 808
    Points
    2 808
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    adapter = new myBaseAdapter (this, myList);

  17. #17
    Membre habitué
    Homme Profil pro
    Inscrit en
    Octobre 2011
    Messages
    281
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Octobre 2011
    Messages : 281
    Points : 161
    Points
    161
    Par défaut
    Merci, donc maintenant est ce bon ? Voilà mon activité :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
     
    package com.pxr.tutorial.json;
     
    import java.util.ArrayList;
    import java.util.HashMap;
     
    import org.json.JSONArray;
    import org.json.JSONException;
    import org.json.JSONObject;
    import com.pxr.tutorial.xmltest.R;
    import android.app.ListActivity;
    import android.os.Bundle;
    import android.util.Log;
    import android.widget.ListView;
     
    public class AttualitaActivity extends ListActivity {
        /** Called when the activity is first created. */
     
     
        private myBaseAdapter adapter = null;
        private ListView lv;
        private ArrayList<HashMap<String, String>> myList ;
        @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());
            }
     
     
            adapter = new myBaseAdapter(this,myList);
    		setListAdapter (adapter);
    		lv = getListView();	
     
        }
    }

  18. #18
    Rédacteur
    Avatar de David55
    Homme Profil pro
    Ingénieur informatique
    Inscrit en
    Août 2010
    Messages
    1 542
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2010
    Messages : 1 542
    Points : 2 808
    Points
    2 808
    Par défaut
    Ca m'a tout l'air!!! Tu arrives à l’exécuter?

  19. #19
    Membre habitué
    Homme Profil pro
    Inscrit en
    Octobre 2011
    Messages
    281
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Octobre 2011
    Messages : 281
    Points : 161
    Points
    161
    Par défaut
    Citation Envoyé par David55 Voir le message
    Ca m'a tout l'air!!! Tu arrives à l’exécuter?
    J'ai un attention sur cette ligne

    Il me dise que la variable n'est jamais utiliser pourtant je fais bien cette instruction :



  20. #20
    Rédacteur
    Avatar de David55
    Homme Profil pro
    Ingénieur informatique
    Inscrit en
    Août 2010
    Messages
    1 542
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2010
    Messages : 1 542
    Points : 2 808
    Points
    2 808
    Par défaut
    C'est normale!

    Ecris plutot:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    lv = getListView();
    lv.setListAdapter (adapter);

Discussions similaires

  1. Réponses: 3
    Dernier message: 05/07/2005, 18h07
  2. problème affichage image
    Par thealpacino dans le forum Balisage (X)HTML et validation W3C
    Réponses: 8
    Dernier message: 30/05/2005, 13h56
  3. [javascript] problème insertion image
    Par Pwill dans le forum Général JavaScript
    Réponses: 6
    Dernier message: 18/05/2005, 16h12
  4. problème dessiner image dans fenêtre
    Par raoulman dans le forum MFC
    Réponses: 5
    Dernier message: 13/12/2004, 15h44
  5. Problème d'image avec DirectX9 et c# VS.net...
    Par lilly_lilly dans le forum DirectX
    Réponses: 1
    Dernier message: 02/03/2004, 14h02

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo