Bonjour à tous
je veux activer mon bouton "ok" d'une alertDialog qui me permet d'ouvrir une nouvelle activite.mais une erreur "force close".
voila les 2 activite ainsi que le main et le manifest:
************principale**********
********************main*****************
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 import java.util.ArrayList; import java.util.HashMap; import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; 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; import android.widget.Toast; public class GuideActivity extends Activity { private ListView maListViewPerso; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //Récupération de la listview créée dans le fichier main.xml maListViewPerso = (ListView) findViewById(R.id.listviewperso); //Création de la ArrayList qui nous permettra de remplire la listView 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; //Création d'une HashMap pour insérer les informations du premier item de notre listView map = new HashMap<String, String>(); //on insère un élément titre que l'on récupérera dans le textView titre créé dans le fichier affichageitem.xml map.put("titre", "Frensh"); //on insère un élément description que l'on récupérera dans le textView description créé dans le fichier affichageitem.xml map.put("description", ""); //on insère la référence à l'image (convertit en String car normalement c'est un int) que l'on récupérera dans l'imageView créé dans le fichier affichageitem.xml map.put("img", String.valueOf(R.drawable.fr)); //enfin on ajoute cette hashMap dans la arrayList listItem.add(map); map = new HashMap<String, String>(); map.put("titre", "English"); map.put("description", ""); map.put("img", String.valueOf(R.drawable.eng)); 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 SimpleAdapter mSchedule = new SimpleAdapter (this.getBaseContext(), listItem, R.layout.affichageitem, new String[] {"img", "titre", "description"}, new int[] {R.id.img, R.id.titre, R.id.description}); //On attribut à notre listView l'adapter que l'on vient de créer maListViewPerso.setAdapter(mSchedule); //Enfin on met un écouteur d'évènement sur notre listView maListViewPerso.setOnItemClickListener(new OnItemClickListener() { @SuppressWarnings("unchecked") public void onItemClick1(AdapterView<?> a, View v, int position, long id) { //on récupère la HashMap contenant les infos de notre item (titre, description, img) HashMap<String, String> map = (HashMap<String, String>) maListViewPerso.getItemAtPosition(position); //on créer une boite de dialogue AlertDialog.Builder adb = new AlertDialog.Builder(GuideActivity.this); //on attribut un titre à notre boite de dialogue adb.setTitle("Sélection Item"); //on insère un message à notre boite de dialogue, et ici on affiche le titre de l'item cliqué adb.setMessage("Votre choix : "+map.get("titre")); //on indique que l'on veut le bouton ok à notre boite de dialogue adb.setPositiveButton("Ok",null);/* new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub Intent intent = new Intent(GuideActivity.this,HelloGoogleMapActivity.class); startActivity(intent); } //public void onCancel(DialogInterface dialog) {} });*/ //on affiche la boite de dialogue adb.show(); } @Override public void onItemClick(AdapterView<?> a, View v, int position, long id) { // TODO Auto-generated method stub //on récupère la HashMap contenant les infos de notre item (titre, description, img) HashMap<String, String> map = (HashMap<String, String>) maListViewPerso.getItemAtPosition(position); //on créé une boite de dialogue AlertDialog.Builder adb = new AlertDialog.Builder(GuideActivity.this); //on attribue un titre à notre boite de dialogue adb.setTitle("Sélection Item"); //on insère un message à notre boite de dialogue, et ici on affiche le titre de l'item cliqué adb.setMessage("Votre choix : "+map.get("titre")); //on indique que l'on veut le bouton ok à notre boite de dialogue adb.setPositiveButton("Ok", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface adb, int which) { // TODO Auto-generated method stub Intent intent = new Intent(GuideActivity.this,HelloGoogleMapActivity.class); startActivity(intent); } //public void onCancel(DialogInterface dialog) {} }); //on affiche la boite de dialogue adb.show(); } }); } }
**************************helloGoogle****************
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 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <ListView android:id="@+id/listviewperso" android:layout_width="fill_parent" android:layout_height="fill_parent" /> </LinearLayout>
************************main1********************
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251 import java.io.IOException; import java.util.List; import java.util.Locale; import com.android.map.HelloItemizedOverlay; import com.android.map.R; import com.google.android.maps.GeoPoint; import com.google.android.maps.MapActivity; import com.google.android.maps.MapController; import com.google.android.maps.MapView; import com.google.android.maps.Overlay; import com.google.android.maps.OverlayItem; import android.app.Activity; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Point; import android.graphics.drawable.Drawable; import android.location.Address; import android.location.Geocoder; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.os.Bundle; import android.util.Log; import android.view.KeyEvent; import android.view.Menu; import android.view.MotionEvent; import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; public class HelloGoogleMapActivity extends MapActivity implements LocationListener{ private MapView mapView; private MapController mc; private LocationManager lm; private MotionEvent event; private double lat = 0; private double lng = 0; LinearLayout linearLayout; TextView tv; HelloItemizedOverlay itemizedoverlay; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main1); MapView mapView = (MapView) findViewById(R.id.mapView); mapView.setBuiltInZoomControls(true); // // lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); // lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1l,1l, this); mc = mapView.getController(); mc.setZoom(17); List<Overlay> mapOverlays = mapView.getOverlays(); Drawable drawable = this.getResources().getDrawable(R.drawable.pink); HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable,this); GeoPoint point = new GeoPoint((int)(36.854128 * 1E6),(int)(10.334809* 1E6)); OverlayItem overlayitem = new OverlayItem(point, "Anthonin de Carthage", "Les thermes dAntonin, situés à Carthage (Tunisie), sont le plus vaste ensemble thermal romain construit sur le sol africain. Ils constituent aussi le seul bâtiment thermal de Carthage dont il subsiste quelques vestiges, en dépit de la prédation féroce qui a sévi sur le site archéologique et dépouillé le monument de ses matériaux."); // mc.setCenter(point); mc.setCenter(point); GeoPoint point1 = new GeoPoint((int)(36.853372* 1E6),(int)(10.32423* 1E6)); OverlayItem overlayitem1 = new OverlayItem(point1, "Musée National de Carthage", "hello"); // mc.setCenter(point1); GeoPoint point2 = new GeoPoint((int)(36.85248* 1E6),(int)(10.323694* 1E6)); OverlayItem overlayitem2 = new OverlayItem(point2, "Byrsa","hello"); //mc.setCenter(point2); GeoPoint point3 = new GeoPoint((int)(36.857768* 1E6),(int)(10.329444* 1E6)); OverlayItem overlayitem3 = new OverlayItem(point3, "Amphithéatre de Carthage", "hello"); //mc.setCenter(point3); GeoPoint point4 = new GeoPoint((int)(36.858128* 1E6),(int)(10.331526* 1E6)); OverlayItem overlayitem4 = new OverlayItem(point4, "Villas Romaines ", "hello"); //mc.setCenter(point4); GeoPoint point5 = new GeoPoint((int)(36.854025* 1E6),(int)(10.323071* 1E6)); OverlayItem overlayitem5 = new OverlayItem(point5, "Acropolium", "hello"); //mc.setCenter(point5); GeoPoint point6 = new GeoPoint((int)(36.856171* 1E6),(int)(10.314832* 1E6)); OverlayItem overlayitem6 = new OverlayItem(point6, "Amphithéatre1 de Carthage", "hello"); //mc.setCenter(point6); GeoPoint point7 = new GeoPoint((int)(36.857545* 1E6),(int)(10.318415* 1E6)); OverlayItem overlayitem7 = new OverlayItem(point7, "Phenix Carthage", "hello"); // mc.setCenter(point7); // GeoPoint point8 = new GeoPoint((int)(36.843087* 1E6),(int)(10.325539* 1E6)); // OverlayItem overlayitem8 = new OverlayItem(point8, "Site archéologique de Carthage"," Fondée dès le IXe siècle av. J.-C. sur le golfe de Tunis, Carthage établit à partir du VIe siècle un empire commercial s'étendant à une grande partie du monde méditerranéen et fut le siège d'une brillante civilisation. Au cours des longues guerres puniques, elle occupa des territoires de Rome, mais celle-ci la détruisit finalement en 146 av. J.-C. Une seconde Carthage, romaine celle-là, fut alors fondée sur ses ruines."); itemizedoverlay.addOverlay(overlayitem); itemizedoverlay.addOverlay(overlayitem1); itemizedoverlay.addOverlay(overlayitem2); itemizedoverlay.addOverlay(overlayitem3); itemizedoverlay.addOverlay(overlayitem4); itemizedoverlay.addOverlay(overlayitem5); itemizedoverlay.addOverlay(overlayitem6); itemizedoverlay.addOverlay(overlayitem7); // itemizedoverlay.addOverlay(overlayitem8); mapOverlays.add(itemizedoverlay); mapView.isSatellite(); lm = (LocationManager) this.getSystemService(LOCATION_SERVICE); lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 10000, 0, this); lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 10000, 0, this); mapView.setClickable(true); } public boolean onTouchEvent(MotionEvent event, MapView mapView) { //---when user lifts his finger--- if (event.getActionIndex()== 1) { GeoPoint point = mapView.getProjection().fromPixels((int) event.getX(),(int) event.getY()); Toast.makeText(getBaseContext(), point.getLatitudeE6() / 1E6 + "," + point.getLongitudeE6() /1E6 ,Toast.LENGTH_SHORT).show(); } return false; } @Override protected boolean isRouteDisplayed() { // TODO Auto-generated method stub return false; } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_S) { mapView.setSatellite(!mapView.isSatellite()); return true; } return super.onKeyDown(keyCode, event); } @Override public void onLocationChanged(Location location) { // TODO Auto-generated method stub lat = location.getLatitude(); lng = location.getLongitude(); //"Location change to : Latitude = " + lat + " Longitude = " + lng // Toast.makeText(getBaseContext(),"Je suis là",Toast.LENGTH_SHORT).show(); // lat = location.getLatitude(); //lng = location.getLongitude(); //"Location change to : Latitude = " + lat + " Longitude = " + lng Toast.makeText(getBaseContext(),"Je suis là",Toast.LENGTH_SHORT).show(); GeoPoint p = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6)); /* OverlayItem overlayitem9 = new OverlayItem(p, "je suis là", null); Drawable dra = this.getResources().getDrawable(R.drawable.man); HelloItemizedOverlay itemizedoverlay1 = new HelloItemizedOverlay(dra,this); List<Overlay> mapOverlays = mapView.getOverlays(); itemizedoverlay1.addOverlay(overlayitem9); mapOverlays.add(itemizedoverlay1); // mc.setCenter(p); mc.animateTo(p); // mc.setCenter(p);*/ } @Override public void onProviderDisabled(String provider) { // TODO Auto-generated method stub // // Log.e("GPS", "provider disabled " + provider); //tv = new TextView(this); //tv.setText(tv.getText()+"\nprovider disabled " + arg0); //setContentView(tv); } @Override public void onProviderEnabled(String provider) { // TODO Auto-generated method stub // Log.e("GPS", "provider enabled " + provider); //tv = new TextView(this); tv.setText(tv.getText()+"\nprovider enabled " + provider); //setContentView(tv); } @Override public void onStatusChanged(String provider, int status, Bundle extras) { // TODO Auto-generated method stub } }
****************manifest************************
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 <?xml version="1.0" encoding="UTF-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <com.google.android.maps.MapView android:id="@+id/mapView" android:layout_width="fill_parent" android:layout_height="fill_parent" android:enabled="true" android:clickable="true" android:apiKey="@string/mapKey" /> <LinearLayout android:id="@+id/zoom" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" /> </LinearLayout>
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 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.map" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <uses-library android:name="com.google.android.maps" /> <activity android:name=".HelloGoogleMapActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".GoogleSearch" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".HelloGallery" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_GPS" /> <uses-permission android:name="android.permission.ACCESS_ASSISTED_GPS" /> <uses-permission android:name="android.permission.LOCATION" /> <uses-sdk android:minSdkVersion="8" /> </manifest>
merci
Partager