Bonjour,

Je veux afficher une liste de produit avec ses informations (stockées dans une base de données dont l'url de son image qui est elle stockée sur un serveur web)

J'ai trouvé un tuto sur internet qui utilise ce principe mais les URLs sont en dure dans le programme contrairement à mon cas où j'utilise une liste dynamique.

Mon problème est que la liste en elle-même n'apparaît même pas dans mon activité et je n'ai aucune erreur dans le log.

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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package com.example.test;
 
public class ListeProduits extends Activity {
 
	ListView list;
 
                    ....................
 
	LazyAdapter adapter2;
 
 
	ArrayList<HashMap<String, String>> listp = new ArrayList<HashMap<String, String>>();
 
	//URL to get JSON Array
	private static String url = "http://xxxx.free.fr/xxxxx.php";
 
	//JSON Node Names 
	public static final String TAG_PRODUIT = "Produit";
	public static final String TAG_PRIX = "Prix";
	public static final String TAG_ENSTOCK = "Quantite";
	public static final String TAG_DESCRIPTION = "Description";
	public static final String TAG_RESTANT = "Restant";
	public static final String TAG_URLIMAGE = "URLimage";
 
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.liste_produits);	
 
        new JSONParse().execute();
 
	    LPProduit = (TextView)findViewById(R.id.LPProduit);
 
                  .....................
 
        listp = new ArrayList<HashMap<String, String>>();
 
    }
 
 
public class JSONParse extends AsyncTask<String, String, JSONArray> {
    	 private ProgressDialog pDialog;
    	@Override
        protected void onPreExecute() {
            super.onPreExecute();
 
 
            pDialog = new ProgressDialog(ListeProduits.this);
            pDialog.setMessage("Chargement des données ...");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(true);
            pDialog.show();
 
    	}
 
    	@Override
        protected JSONArray doInBackground(String... args) {
 
    		JSONParser jParser = new JSONParser();
    		// Getting JSON from URL
    		JSONArray json = jParser.getJSONFromUrl(url);
    		return json;
 
    	}
    	 @Override
         protected void onPostExecute(JSONArray json) {
    		 pDialog.dismiss();
    		 try {
    				// On récupère le tableau JSON de l'URL
 
    				for(int i = 0; i < json.length(); i++){
    				JSONObject c = json.getJSONObject(i);
 
    				// On stocke les valeurs JSON dans une variable
    				produit = c.getString(TAG_PRODUIT);
    				prix = c.getString(TAG_PRIX);
    				dispo = c.getString(TAG_ENSTOCK);
    				description = c.getString(TAG_DESCRIPTION);
    				URLimage = c.getString(TAG_URLIMAGE);
 
    				restant = Integer.parseInt(dispo);
 
 
    				// Adding value HashMap key => value
    				HashMap<String, String> map = new HashMap<String, String>();
 
    				map.put(TAG_PRODUIT, produit);
    				map.put(TAG_PRIX, prix +" euros");
 
    				if(restant == 0) {
    					map.put(TAG_ENSTOCK, "Rupture de stock");
    				}
    				else {
    					map.put(TAG_ENSTOCK, "En Stock");
    				}
 
    				map.put(TAG_DESCRIPTION, description);
 
    				if(restant != 0 && restant < 5) {
    					Restant = "Il ne reste plus que "+restant+" exemplaires";
    					map.put(TAG_RESTANT, Restant);
	            	}  		            	
    				else {
    					map.put(TAG_RESTANT, "null");
    				}
 
    				map.put(TAG_URLIMAGE, URLimage);
 
    				listp.add(map);
 
    				list=(ListView)findViewById(R.id.list);
 
    				adapter2 = new LazyAdapter(ListeProduits.this, listp);
 
    				list.setAdapter(adapter);
 
 
    				list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
 
    		            @Override
    		            public void onItemClick(AdapterView<?> parent, View view,
    		                                    int position, long id) {
 
    		            ...................
 
    		            }
    		        });
 
 
    				}
    		} catch (JSONException e) {
    			e.printStackTrace();
    		}	 
    	 }
    }
LazyAdapter :

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
package com.example.test;
 
public class LazyAdapter extends BaseAdapter {
 
    private Activity activity;
    private List<? extends Map<String, String>> data;
    private static LayoutInflater inflater=null;
    public ImageLoader imageLoader; 
 
    public LazyAdapter(Activity a,
			List<? extends Map<String, String>> data) {
    	this.activity = a;
        this.data=data;
        inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        imageLoader = new ImageLoader(activity.getApplicationContext());
 
        Log.i("Data",data.toString());
    }
 
    @Override
	public int getCount() {
		// TODO Auto-generated method stub
		return data.size();
	}
 
	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}
 
	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}
 
    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        View vi=convertView;
 
        if(convertView==null) {
 
        vi = inflater.inflate(R.layout.list_v, null);
 
        TextView Produit=(TextView)vi.findViewById(R.id.Ligne1v2);;
        ImageView ImageProduit=(ImageView)vi.findViewById(R.id.ListeProduitImage);
        TextView Prix = (TextView)vi.findViewById(R.id.Ligne2v2);
        TextView Quantite = (TextView)vi.findViewById(R.id.Ligne4);
 
        Produit.setText(data.get(position).get("Produit"));
        Prix.setText(data.get(position).get("Prix"));
        Quantite.setText(data.get(position).get("Quantite"));
        imageLoader.DisplayImage(data.get(position).get("URLimage"), ImageProduit);
 
    }
		return vi;      
    }
 
}
J'ai l'impression qu'il n'accède pas au getView

merci d'avance