Bonjour,

J'ai une listview d'éléments qui est la suivante :

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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package activite;
 
public class List2 extends Activity implements OnItemClickListener{
 
	protected ProgressDialog myProgressDialog;
	final Handler uiThreadCallback = new Handler();
	int i = 0;
	String siret;
	public final static String ITEM_TITLE = "title";  
	public final static String ITEM_CAPTION = "caption";
	Button boutonTerminer;
	ListSeparer adapter;
 
	Map<String,String> item;
 
	ArrayList<String> returnedValueNom = new ArrayList<String>();
	ArrayList<Double> returnedValuePrix = new ArrayList<Double>();
	ArrayList<Integer> returnedValueType = new ArrayList<Integer>();
 
	public Map<String,?> createItem(String title, String caption) {  
		item = new HashMap<String,String>();  
		item.put(ITEM_TITLE, title);  
		item.put(ITEM_CAPTION, caption);  
		return item;  
	} 
 
	@Override 
	public void onCreate(Bundle icicle) {  
 
		super.onCreate(icicle); 
		Intent thisIntent = getIntent();
		siret = thisIntent.getExtras().getString("siret");
 
		myProgressDialog = ProgressDialog.show(ListPlat2.this,"", "Chargement", true);
 
        final Runnable runInUIThread = new Runnable() {
    	    public void run() {
    	    	affiche_liste();    	     
    	    }
    	};
 
    	new Thread() {
		@Override public void run() {
			  	remplir_liste();
			  	myProgressDialog.dismiss();
			  	uiThreadCallback.post(runInUIThread);
		    }
		}.start();
 
	}
 
    public void remplir_liste() {
 
    	getServerData();
        String[] valueNom = returnedValueNom.toArray(new String[returnedValueNom.size()]);    	
        Double[] valuePrix = returnedValuePrix.toArray(new Double[returnedValuePrix.size()]);
        Integer[] valueType = returnedValueType.toArray(new Integer[returnedValueType.size()]);
 
        adapter = new ListSeparer(this);
        List<Map<String,?>> entree = new LinkedList<Map<String,?>>();
        List<Map<String,?>> plat = new LinkedList<Map<String,?>>();
        List<Map<String,?>> dessert = new LinkedList<Map<String,?>>();
 
        i=0;
        while(i < valueNom.length)
        {
        	if(valueType[i]== 1)
        	{
        		entree.add(createItem(valueNom[i], (String.valueOf(valuePrix[i]))+" €")); 
        	}
        	i++;
        }
        adapter.addSection("Entrées", new SimpleAdapter(this, entree, R.layout.list_complex, new String[] { ITEM_TITLE, ITEM_CAPTION }, new int[] { R.id.list_complex_title, R.id.list_complex_caption }));
 
        i=0;
        while(i < valueNom.length)
        {
        	if(valueType[i]== 2)
        	{
        		plat.add(createItem(valueNom[i], (String.valueOf(valuePrix[i]))+" €")); 
        	}
        	i++;
        }
		adapter.addSection("Plats", new SimpleAdapter(this, plat, R.layout.list_complex, new String[] { ITEM_TITLE, ITEM_CAPTION }, new int[] { R.id.list_complex_title, R.id.list_complex_caption }));
 
		i=0;
		while(i < valueNom.length)
		{
			if(valueType[i]== 3)
			{
				dessert.add(createItem(valueNom[i], (String.valueOf(valuePrix[i]))+" €")); 
			}
			i++;
		}
		adapter.addSection("Desserts", new SimpleAdapter(this, dessert, R.layout.list_complex, new String[] { ITEM_TITLE, ITEM_CAPTION }, new int[] { R.id.list_complex_title, R.id.list_complex_caption }));
 
	}
 
	public void affiche_liste() {
 
		boutonTerminer = new Button(this);
		boutonTerminer.setText("Terminer la commande");
		ListView list = new ListView(this);  
		list.addFooterView(boutonTerminer);
		list.setAdapter(adapter);
		list.setOnItemClickListener(this);
		this.setContentView(list); 
	}
 
	public static final String strURL = "URL";
 
	private void getServerData() {
		InputStream is = null;
		String result = "";
 
		// CHOIX REQUETE :
		ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
		nameValuePairs.add(new BasicNameValuePair("siret", siret));
 
		// CONNEXION :
		try 
		{
			HttpClient httpclient = new DefaultHttpClient();
			HttpPost httppost = new HttpPost(strURL);
			httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
			HttpResponse response = httpclient.execute(httppost);
			HttpEntity entity = response.getEntity();
			is = entity.getContent();
		}
		catch(Exception e)
		{
			Log.e("log_tag", "Error in http connection ",e);
		}
 
		// CONVERSION REQUETE EN 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);
		}
 
		// AFFICHAGE RESULTAT
		try
		{
			JSONArray jArray = new JSONArray(result);
			for(int i=0;i<jArray.length();i++){
				JSONObject json_data = jArray.getJSONObject(i);
				// Résultats de la requête : json_data.getInt("ID_ville")
				//returnString += jArray.getJSONObject(i)+"\n";
				returnedValueNom.add(json_data.getString("nom"));
				returnedValuePrix.add(json_data.getDouble("prix"));
				returnedValueType.add(json_data.getInt("type_plat"));
			}
		}
		catch(JSONException e)
		{
			Log.e("log_tag", "Error parsing data:",e);
		}
	}
 
	public void onItemClick(AdapterView<?> a, View v, int position, long id) {
		// TODO Auto-generated method stub
 
		AjouterPanier dialog = new AjouterPanier(v.getContext(), item.get(ITEM_TITLE));
        dialog.setTitle("Ajouter à la commande :");
    	dialog.show();      
	}
}
Implémentée à l'aide de cette 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
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
public class ListSeparer extends BaseAdapter {
 
 
	public final Map<String,Adapter> sections = new LinkedHashMap<String,Adapter>();  
    public final ArrayAdapter<String> headers;  
    public final static int TYPE_SECTION_HEADER = 0;  
 
	public ListSeparer(Context context) {
               //pour les entetes j'utilise le fichier list_header.xml
		headers = new ArrayAdapter<String>(context, R.layout.list_header); 
	}
 
	//méthode pour ajouter dans le header le nom de ma catégorie et dans sections le nom et un objet adapter
	 public void addSection(String section, Adapter adapter) {  
		 this.headers.add(section);  
		 this.sections.put(section, adapter);  
      }  
	 //Renvoi la position d'un clique
	  public Object getItem(int position) {  
		        for(Object section : this.sections.keySet()) {  
		            Adapter adapter = sections.get(section);  
		           int size = adapter.getCount() + 1;  
 
		          // récupération de la position dans la section 
		            if(position == 0) return section;  
		            if(position < size) return adapter.getItem(position - 1);  
 
		           // passe à la section suivant  
		            position -= size;  
	        }  
		         return null;  
	    }
	  // renvoi le nombre d'item
	   public int getCount() {  
           // 	total de l'ensemble des sections, plus une pour chaque tête de section
           int total = 0;  
           for(Adapter adapter : this.sections.values())  
               total += adapter.getCount() + 1;  
           return total;  
       }  
 
       public int getViewTypeCount() {  
            int total = 1;  
           for(Adapter adapter : this.sections.values())  
               total += adapter.getViewTypeCount();  
           return total;  
       }  
 
        public int getItemViewType(int position) {  
            int type = 1;  
            for(Object section : this.sections.keySet()) {  
                Adapter adapter = sections.get(section);  
                int size = adapter.getCount() + 1;  
 
                // Récupération de la position dans la section
                if(position == 0) return TYPE_SECTION_HEADER;  
                if(position < size) return type + adapter.getItemViewType(position - 1);  
 
                // passe a la section suivante moins un par l'entête 
                position -= size;  
                type += adapter.getViewTypeCount();  
            }  
            return -1;  
        }  
 
        public boolean areAllItemsSelectable() {  
            return false;  
        }  
 
        public boolean isEnabled(int position) {  
            return (getItemViewType(position) != TYPE_SECTION_HEADER);  
        } 
 
 
 
        public View getView(int position, View convertView, ViewGroup parent) {  
            int sectionnum = 0;  
            for(Object section : this.sections.keySet()) {  
                Adapter adapter = sections.get(section);  
                int size = adapter.getCount() + 1;  
 
                // Récupération de la position dans la section  
                if(position == 0) return headers.getView(sectionnum, convertView, parent);  
                if(position < size) return adapter.getView(position - 1, convertView, parent);  
 
                // otherwise jump into next section  
                position -= size;  
                sectionnum++;  
            }  
            return null;  
        }  
 
 
        public long getItemId(int position) {  
            return position;  
        }  
}

Dans la méthode "onItemClick" je voudrais envoyer en paramètre le titre de l'item selectionné. Seulement si je met je retourne toujours le titre du dernier élément de la listeview.

Si je met
Code : Sélectionner tout - Visualiser dans une fenêtre à part
adapter.getItem(position)
je retourne tout l'objet qui s'affiche {caption : ..... , title : .....}

Comment faire pour ne retourner que le titre de l'item suivant l'item sélectionné ?

Merci.