Bonjour.

J'ai actuellement un code qui fonctionne mais qui ne correspond pas à ce que je veux faire au final.

J'ai une listView alimentée par un JSON généré à la volée. J'envoie les paramètres de ma requête pour la génération, à savoir la LIMIT de ma requête ($start et $end).
Je récupère un code, un titre et une photo.
J'affiche le titre à côté de la photo correspondante.

Ce que je voudrais c'est :
- La même présentation de ma listView.
- Un chargement asynchrone des photos.
- Une mise en cache des photos.
- Charger les données suivantes (changer la LIMIT) en scrollant vers le bas.

Le problème est qu'au fur et à mesure je me demande si ce que j'ai fait est bien, optimisé et si je peux ajouter ce que je veux à ce que j'ai fait.

Voilà mon code :
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
package com.my.package;
 
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
 
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
 
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.SimpleAdapter;
 
public class Announces extends Activity{
 
	Context context;
	private static final String SOAP_ACTION = "getData";
	private static final String OPERATION_NAME = "getData";
	private static final String WSDL_TARGET_NAMESPACE = "http://www.monsite.com/webservice/";
	private static final String SOAP_ADDRESS = "http://www.monsite.com/webservice/soapserver.php";
 
	public final static String ITEM_CODE = "code";
	public final static String ITEM_TITLE = "title";
	public final static String ITEM_PHOTO = "photo";
	public Map<String,?> createItem(String code, String photo, String title) {
		Map<String,String> item = new HashMap<String,String>();
		item.put(ITEM_CODE, code);
		item.put(ITEM_PHOTO, photo);
		item.put(ITEM_TITLE, title);
		return item;
	}
 
	private ListView lvListe;
 
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.announces);
		context = this;
 
		lvListe = (ListView) findViewById(R.id.ListAnnounces);
 
		SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE, OPERATION_NAME);
 
		request.addProperty("start", "0");
		request.addProperty("end", "10");
 
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		envelope.dotNet = true;
 
		envelope.setOutputSoapObject(request);
 
		HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
 
		ArrayList<HashMap<String, Object>> items = new ArrayList<HashMap<String, Object>>();
		HashMap<String, Object> map;
 
		try{
			httpTransport.call(SOAP_ACTION, envelope);
			Object response = envelope.getResponse();
			String jString = response.toString();
			try {
				JSONArray jsonArray = new JSONArray(jString);
				for (int i = 0; i < jsonArray.length(); i++) {
					JSONObject jsonObject = jsonArray.getJSONObject(i);
					String AttrCode = jsonObject.getString("code");
					String AttrPhoto = jsonObject.getString("photo");
					String AttrTitle = jsonObject.getString("title");
					map = new HashMap<String, Object>();
					URL pictureURL = new URL(AttrPhoto);
					Bitmap bitmap = BitmapFactory.decodeStream(pictureURL.openStream());
					bitmap = getResizedBitmap(bitmap, 80, 58);
					map.put(ITEM_CODE, AttrCode);
					map.put(ITEM_PHOTO, bitmap);
					map.put(ITEM_TITLE, AttrTitle);
					items.add(map);
				}
			}catch (JSONException e){
				lvListe.setFilterText(e.toString());
			}
		}catch (Exception exception){
			lvListe.setFilterText(exception.toString());
		}
 
		SimpleAdapter mSchedule = new SimpleAdapter (
														this,
														items,
														R.layout.list_announces,
														new String[] {ITEM_PHOTO, ITEM_TITLE},
														new int[] {R.id.list_announces_photo, R.id.list_announces_title}
													);
 
		mSchedule.setViewBinder(new MyViewBinder());
		lvListe.setAdapter(mSchedule);
		lvListe.setOnItemClickListener(new OnItemClickListener() {
			@SuppressWarnings("unchecked")
			public void onItemClick(AdapterView<?> a, View v, int position, long id) {
				HashMap<String, Object> map = (HashMap<String, Object>) lvListe.getItemAtPosition(position);
				Intent intent = new Intent(context, Announce.class);
				intent.putExtra("code", (String) map.get(ITEM_CODE));
				context.startActivity(intent);
			}
		});
	}
 
	public Bitmap getResizedBitmap(Bitmap bm, int newWidth, int newHeight) {
		int width = bm.getWidth();
		int height = bm.getHeight();
		float scaleWidth = ((float) newWidth) / width;
		float scaleHeight = ((float) newHeight) / height;
 
		Matrix matrix = new Matrix();
 
		matrix.postScale(scaleWidth, scaleHeight);
 
		Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false);
		return resizedBitmap;
	}
}
Pouvez-vous me donner votre avis, vos conseils ?
Je précise que je débute dans le développement Android

Merci.