Bonjour, j'ai cette activity :

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
176
 
package com.android.webtrack;
 
 
import java.util.ArrayList;
import java.util.HashMap;
 
import org.w3c.dom.Element;
 
import XMLSeeker.RechercheXML;
import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.AdapterView.OnItemClickListener;
 
public class SelectionIncidentsActivity extends Activity {
 
	/*
	 * Préparation de notre listview
	 */
	private ListView lv1;
	Element el;
 
	@Override
	public void onCreate(Bundle icicle)
	{
 
 
	super.onCreate(icicle);
	setContentView(R.layout.main_anomalies);
 
	final RechercheXML xmlSeeker = new RechercheXML("/sdcard/CollectMobile_Data/incidents/incidents.xml");
 
	ArrayList <String> Menus = xmlSeeker.getPremiersNiveaux();
 
	   //Récupération de la listview créée dans le fichier main.xml
    lv1 = (ListView) findViewById(R.id.ListView01);
 
    //Création de la ArrayList qui nous permettra de remplire la listView
    final ArrayList<HashMap<String, String>> listItem = new ArrayList<HashMap<String, String>>();
 
    //On déclare la HashMap qui contiendra les informations pour un item
    HashMap<String, String> map;
 
    for (int k=0;k<Menus.size();k=k+2){
    map = new HashMap<String, String>();
	map.put("nom", Menus.get(k));
	map.put("cle", Menus.get(k+1));
	map.put("img", String.valueOf(R.drawable.inc));
	listItem.add(map); 
    }
 
 
	//Création d'un SimpleAdapter qui se chargera de mettre les items présent dans notre list (listItem) dans la vue affichageitem
    final SimpleAdapter mSchedule = new SimpleAdapter (this.getBaseContext(), listItem, R.layout.liste_anomalies,
           new String[] {"img", "nom", "cle"}, new int[] {R.id.imgAnomalie, R.id.nomAnomalie, R.id.cle});
 
    //On attribut à notre listView l'adapter que l'on vient de créer
    	lv1.setAdapter(mSchedule);
 
 
    //Enfin on met un écouteur d'évènement sur notre listView
    	lv1.setOnItemClickListener(new OnItemClickListener() {
 
 
 
    		public void onItemClick(AdapterView<?> a, View v, int position, long id) {
			//on récupère la HashMap contenant les infos de notre item (titre, description, img)
    		@SuppressWarnings("unchecked")
				HashMap<String, String> map = (HashMap<String, String>) lv1.getItemAtPosition(position);
    		//on créer une boite de dialogue
 
    				ArrayList <String> ProchainsNiveaux = new ArrayList <String> ();
    				String nomRecup = map.get("nom");
    				String cleRecup = map.get("cle");
 
 
    				el = xmlSeeker.getElementByNameAndCle(nomRecup, cleRecup);
 
    				if (el == null){
 
    					el = xmlSeeker.getItemByNameAndCle(nomRecup, cleRecup);
    				}
 
    				ProchainsNiveaux = xmlSeeker.getNiveauxSuivants(el);
 
    				if (ProchainsNiveaux != null){
 
    					map.clear();
        				listItem.clear();
 
    					for(int j=0;j<ProchainsNiveaux.size();j=j+2){
 
    						String mapitem = ProchainsNiveaux.get(j);
    						String cle = ProchainsNiveaux.get(j+1);
 
    						map = new HashMap<String, String>();
    						map.put("nom", mapitem);
    						map.put("cle", cle);
    						map.put("img", String.valueOf(R.drawable.inc));
    						listItem.add(map); 
 
    					}
 
    					lv1.setAdapter(mSchedule);
 
    				}
 
 
    	/*	Intent intent= getIntent();
    		intent.putExtra("SELECTION", map.get("nom"));
    		setResult(RESULT_OK, intent);
    		finish(); */
    	}
 
 
     });
 
 
 
}
 
	protected HashMap<String, String> getItemAtPosition(int position) {
	// TODO Auto-generated method stub
		return null;
	}
 
	public boolean onKeyDown(int i, KeyEvent event) {
 
		  // only intercept back button press
		  if (i == KeyEvent.KEYCODE_BACK) {
 
		ArrayList <String> NiveauxPrecedents = new ArrayList <String> ();
		NiveauxPrecedents = xmlSeeker.remonterNiveaux(el);
 
				if (NiveauxPrecedents != null){
 
					map.clear();
					listItem.clear();
 
						for(int j=0;j<NiveauxPrecedents.size();j=j+2){
 
							String mapitem = NiveauxPrecedents.get(j);
							String cle = NiveauxPrecedents.get(j+1);
 
							map = new HashMap<String, String>();
							map.put("nom", mapitem);
							map.put("cle", cle);
							map.put("img", String.valueOf(R.drawable.inc));
							listItem.add(map); 
 
						}
 
						lv1.setAdapter(mSchedule);
 
				}
 
				else 
 
				{
			  finish();
		      return true; 
				}
 
		    }
 
		return true;
	}
 
 
 
}
J'aimerais passer les paramètres map, listItem, mSchedule et xmlSeeker à onKeyDown pour qu'il puisse tenir compte de l'état courant de ma liste, pour savoir si jdois revenir en arrière dans ma liste ou quitter l'activity.

Voilà, je cherche à savoir comment faire ça de manière propre.

Edit : A savoir que dans le onKeydown actuellement j'ai des erreurs sur les paramètres que je viens de vous citer.

MERCI !!