Bonjour a tous,
Je suis un débutant en programmation sous Android et je me retrouve confronté à un souci concernant la mise en page de mon "Activity".
Mon appli est une "Activity" qui comprend 12 TextView, 12 EditText, 2 CheckBox, 2 GridView, 1 Spinner et un Button.
Voici mon code:
String.xml :
activity_main.xml :
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 <?xml version="1.0" encoding="utf-8"?> <resources> <string name="app_name">TestPositionnement</string> <string name="hello_world">Hello world!</string> <string name="action_settings">Settings</string> <!-- Info des boutons --> <string name="save">Sauvegarde</string> <!-- Info pour la partie Particulier de Interieur du Bien --> <string name="surf_hab">Surface habitable</string> <string name="surf_sej">Surface séjour</string> <string name="wc">WC</string> <string name="garage">Garage(s)</string> <string name="piece">Pièce(s)</string> <string name="chambre">Chambre(s)</string> <string name="park_int">Parking intérieur</string> <string name="park_ext">Parking extérieur</string> <string name="sdb">Salle(s) de bains</string> <string name="sd">Salle(s) d\'eau</string> <string name="ch_rdc">Chambre(s) en RDC</string> <string name="etage">Etage(s)</string> <string name="plain_pied">Plain pied</string> <string name="sur_sous_sol">Sur sous-sol</string> <string name="cuisine">Cuisine</string> <string-array name="liste_cui"> <item>Aménagée</item> <item>Equipée</item> <item>Américaine</item> <item>Coin cuisine</item> <item>Vide</item> </string-array> <string name="type_chauff">Type de chauffage</string> <string-array name="liste_type_chauff"> <item>Bois</item> <item>Gaz</item> <item>Fuel</item> <item>Electrique</item> <item>Cheminée</item> <item>Clim. reversible</item> <item>Sol</item> <item>Solaire</item> <item>Géothermie</item> <item>Insert</item> </string-array> <string name="nature_chauff">Nature du chauffage</string> <string name="chauffage">Chauffage</string> <string-array name="liste_nat_chauff"> <item>Collectif</item> <item>Individuel</item> <item>Central</item> <item>Aucun</item> </string-array> </resources>
MainActivity.java :
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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:gravity="center" > <!-- 1ere ligne = texte + champs editable --> <LinearLayout android:layout_height="wrap_content" android:orientation="horizontal" android:layout_width="match_parent" > <TextView android:id="@+id/text_view_surf_hab" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:text="@string/surf_hab" /> <EditText android:id="@+id/surf_hab_edit" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="25dp" android:ems="5" android:inputType="number" android:textSize="12sp" /> </LinearLayout> <!-- 2eme ligne = texte + champs editable --> <LinearLayout android:layout_height="wrap_content" android:orientation="horizontal" android:layout_width="match_parent" > <TextView android:id="@+id/text_view_surf_sej" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:text="@string/surf_sej" /> <EditText android:id="@+id/surf_sej_edit" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="25dp" android:ems="5" android:inputType="number" android:textSize="12sp" /> </LinearLayout> <!-- 3eme ligne = texte + champs editable --> <LinearLayout android:layout_height="wrap_content" android:orientation="horizontal" android:layout_width="match_parent" > <TextView android:id="@+id/text_view_wc" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:text="@string/wc" /> <EditText android:id="@+id/wc_edit" android:layout_width="wrap_content" android:layout_height="wrap_content" android:ems="5" android:inputType="number" android:textSize="12sp" /> </LinearLayout> <!-- 4eme ligne = texte + champs editable --> <LinearLayout android:layout_height="wrap_content" android:orientation="horizontal" android:layout_width="match_parent" > <TextView android:id="@+id/text_view_garage" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:text="@string/garage" /> <EditText android:id="@+id/garage_edit" android:layout_width="wrap_content" android:layout_height="wrap_content" android:ems="5" android:inputType="number" android:textSize="12sp" /> </LinearLayout> <!-- 5eme ligne = texte + champs editable --> <LinearLayout android:layout_height="wrap_content" android:orientation="horizontal" android:layout_width="match_parent" > <TextView android:id="@+id/text_view_piece" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:text="@string/piece" /> <EditText android:id="@+id/piece_edit" android:layout_width="wrap_content" android:layout_height="wrap_content" android:ems="5" android:inputType="number" android:textSize="12sp" /> </LinearLayout> <!-- 6eme ligne = texte + champs editable --> <LinearLayout android:layout_height="wrap_content" android:orientation="horizontal" android:layout_width="match_parent" > <TextView android:id="@+id/text_view_chambre" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:text="@string/chambre" /> <EditText android:id="@+id/chambre_edit" android:layout_width="wrap_content" android:layout_height="wrap_content" android:ems="5" android:inputType="number" android:textSize="12sp" /> </LinearLayout> <!-- 7eme ligne = texte + champs editable --> <LinearLayout android:layout_height="wrap_content" android:orientation="horizontal" android:layout_width="match_parent" > <TextView android:id="@+id/text_view_park_int" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:text="@string/park_int" /> <EditText android:id="@+id/park_int_edit" android:layout_width="wrap_content" android:layout_height="wrap_content" android:ems="5" android:inputType="number" android:textSize="12sp" /> </LinearLayout> <!-- 8eme ligne = texte + champs editable --> <LinearLayout android:layout_height="wrap_content" android:orientation="horizontal" android:layout_width="match_parent" > <TextView android:id="@+id/text_view_park_ext" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:text="@string/park_ext" /> <EditText android:id="@+id/park_ext_edit" android:layout_width="wrap_content" android:layout_height="wrap_content" android:ems="5" android:inputType="number" android:textSize="12sp" /> </LinearLayout> <!-- 9eme ligne = texte + champs editable --> <LinearLayout android:layout_height="wrap_content" android:orientation="horizontal" android:layout_width="match_parent" > <TextView android:id="@+id/text_view_sdb" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:text="@string/sdb" /> <EditText android:id="@+id/sdb_edit" android:layout_width="wrap_content" android:layout_height="wrap_content" android:ems="5" android:inputType="number" android:textSize="12sp" /> </LinearLayout> <!-- 10eme ligne = texte + champs editable --> <LinearLayout android:layout_height="wrap_content" android:orientation="horizontal" android:layout_width="match_parent" > <TextView android:id="@+id/text_view_sd" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:text="@string/sd" /> <EditText android:id="@+id/sd_edit" android:layout_width="wrap_content" android:layout_height="wrap_content" android:ems="5" android:inputType="number" android:textSize="12sp" /> </LinearLayout> <!-- 11eme ligne = texte + champs editable --> <LinearLayout android:layout_height="wrap_content" android:orientation="horizontal" android:layout_width="match_parent" > <TextView android:id="@+id/text_view_ch_rdc" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:text="@string/ch_rdc" /> <EditText android:id="@+id/ch_rdc_edit" android:layout_width="wrap_content" android:layout_height="wrap_content" android:ems="5" android:inputType="number" android:textSize="12sp" /> </LinearLayout> <!-- 12eme ligne = texte + champs editable --> <LinearLayout android:layout_height="wrap_content" android:orientation="horizontal" android:layout_width="match_parent" > <TextView android:id="@+id/text_view_etage" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:text="@string/etage" /> <EditText android:id="@+id/etage_edit" android:layout_width="wrap_content" android:layout_height="wrap_content" android:ems="5" android:inputType="number" android:textSize="12sp" /> </LinearLayout> <!-- 13eme ligne = check box --> <LinearLayout android:layout_height="wrap_content" android:orientation="horizontal" android:layout_width="match_parent" > <CheckBox android:id="@+id/check_box_plain_pied" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:text="@string/plain_pied" /> </LinearLayout> <!-- 14eme ligne = check box --> <LinearLayout android:layout_height="wrap_content" android:orientation="horizontal" android:layout_width="match_parent" > <CheckBox android:id="@+id/check_box_sur_sous_sol" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:text="@string/sur_sous_sol" /> </LinearLayout> <!-- 15eme ligne = texte --> <LinearLayout android:layout_height="wrap_content" android:orientation="horizontal" android:layout_width="match_parent" android:gravity="center" android:layout_gravity="left"> <TextView android:id="@+id/text_view_titre_cuisine" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/cuisine" /> </LinearLayout> <!-- 16eme ligne = grid view --> <LinearLayout android:layout_height="match_parent" android:orientation="horizontal" android:layout_width="match_parent" android:gravity="center" android:layout_gravity="left"> <GridView android:id="@+id/liste_cuisine" android:layout_width="match_parent" android:layout_height="match_parent" android:choiceMode="multipleChoice" android:entries="@array/liste_cui" android:gravity="center" android:textSize="8sp" android:numColumns="auto_fit" android:stretchMode="columnWidth" /> </LinearLayout> <!-- 17eme ligne = texte --> <LinearLayout android:layout_height="wrap_content" android:orientation="horizontal" android:layout_width="match_parent" android:gravity="center" android:layout_gravity="left"> <TextView android:id="@+id/text_view_titre_type_chauff" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/type_chauff" /> </LinearLayout> <!-- 18eme ligne = grid view --> <LinearLayout android:layout_height="match_parent" android:orientation="horizontal" android:layout_width="match_parent" android:gravity="center" android:layout_gravity="left"> <GridView android:id="@+id/liste_chauff" android:layout_width="match_parent" android:layout_height="match_parent" android:choiceMode="multipleChoice" android:entries="@array/liste_type_chauff" android:gravity="center" android:textSize="12sp" android:numColumns="auto_fit" android:stretchMode="columnWidth" /> </LinearLayout> <!-- 19eme ligne = texte --> <LinearLayout android:layout_height="wrap_content" android:orientation="horizontal" android:layout_width="match_parent" android:gravity="center" android:layout_gravity="left"> <TextView android:id="@+id/text_view_titre_nat_chauff" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/nature_chauff" /> </LinearLayout> <!-- 20eme ligne = spinner --> <LinearLayout android:layout_height="wrap_content" android:orientation="horizontal" android:layout_width="match_parent" android:gravity="center" android:layout_gravity="left"> <Spinner android:id="@+id/spinner_nat_chauff" android:layout_width="wrap_content" android:layout_height="wrap_content" android:prompt="@string/chauffage" /> </LinearLayout> <!-- 21eme ligne = bouton --> <LinearLayout android:layout_height="wrap_content" android:orientation="horizontal" android:layout_width="match_parent" android:gravity="center" android:layout_gravity="left"> <Button android:id="@+id/buttonSaveIntBien" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/save" /> </LinearLayout> </LinearLayout> </ScrollView>
Maintenant je vais vous présenter mes deux problèmes.
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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319 package com.example.testpositionnement; import android.app.Activity; import android.graphics.Typeface; import android.os.Bundle; import android.text.SpannableString; import android.text.style.StyleSpan; import android.text.style.UnderlineSpan; import android.view.KeyEvent; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.CheckBox; import android.widget.EditText; import android.widget.GridView; import android.widget.Spinner; import android.widget.TextView; import android.widget.Toast; import android.widget.AdapterView.OnItemClickListener; import android.widget.AdapterView.OnItemSelectedListener; import android.widget.TextView.OnEditorActionListener; public class MainActivity extends Activity { TextView titre1; TextView titre2; TextView titre3; EditText surfHab; EditText surfSej; EditText wc; EditText garage; EditText piece; EditText chambre; EditText parkInt; EditText parkExt; EditText sdb; EditText sd; EditText chRDC; EditText etage; CheckBox plainPied; CheckBox surSousSol; GridView table1; GridView table2; String[] elements1; String[] elements2; Spinner spinner; Button save; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Mettre les titres en gras et souligner titre1 = (TextView) findViewById(R.id.text_view_titre_cuisine); String tempString1 = titre1.getText().toString(); SpannableString spanString1 = new SpannableString(tempString1); spanString1.setSpan(new UnderlineSpan(), 0, spanString1.length(), 0); spanString1.setSpan(new StyleSpan(Typeface.BOLD), 0, spanString1.length(), 0); titre1.setText(spanString1); titre2 = (TextView) findViewById(R.id.text_view_titre_type_chauff); String tempString2 = titre2.getText().toString(); SpannableString spanString2 = new SpannableString(tempString2); spanString2.setSpan(new UnderlineSpan(), 0, spanString2.length(), 0); spanString2.setSpan(new StyleSpan(Typeface.BOLD), 0, spanString2.length(), 0); titre2.setText(spanString2); titre3 = (TextView) findViewById(R.id.text_view_titre_nat_chauff); String tempString3 = titre3.getText().toString(); SpannableString spanString3 = new SpannableString(tempString3); spanString3.setSpan(new UnderlineSpan(), 0, spanString3.length(), 0); spanString3.setSpan(new StyleSpan(Typeface.BOLD), 0, spanString3.length(), 0); titre3.setText(spanString3); //Ecoute des textedit surfHab = (EditText) findViewById(R.id.surf_hab_edit); surfHab.setOnEditorActionListener(new OnEditorActionListener () { public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { // Si le champ n'est pas vide if (surfHab.getText().toString() != null && surfHab.getText().toString().trim().length() > 0) { // On recupere la valeur de l'EditText //namePlayer1 = name1.getText().toString(); return false; } return true; } }); surfSej = (EditText) findViewById(R.id.surf_sej_edit); surfSej.setOnEditorActionListener(new OnEditorActionListener () { public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { // Si le champ n'est pas vide if (surfSej.getText().toString() != null && surfSej.getText().toString().trim().length() > 0) { // On recupere la valeur de l'EditText //namePlayer1 = name1.getText().toString(); return false; } return true; } }); wc = (EditText) findViewById(R.id.wc_edit); wc.setOnEditorActionListener(new OnEditorActionListener () { public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { // Si le champ n'est pas vide if (wc.getText().toString() != null && wc.getText().toString().trim().length() > 0) { // On recupere la valeur de l'EditText //namePlayer1 = name1.getText().toString(); return false; } return true; } }); garage = (EditText) findViewById(R.id.garage_edit); garage.setOnEditorActionListener(new OnEditorActionListener () { public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { // Si le champ n'est pas vide if (garage.getText().toString() != null && garage.getText().toString().trim().length() > 0) { // On recupere la valeur de l'EditText //namePlayer1 = name1.getText().toString(); return false; } return true; } }); piece = (EditText) findViewById(R.id.piece_edit); piece.setOnEditorActionListener(new OnEditorActionListener () { public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { // Si le champ n'est pas vide if (piece.getText().toString() != null && piece.getText().toString().trim().length() > 0) { // On recupere la valeur de l'EditText //namePlayer1 = name1.getText().toString(); return false; } return true; } }); chambre = (EditText) findViewById(R.id.chambre_edit); chambre.setOnEditorActionListener(new OnEditorActionListener () { public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { // Si le champ n'est pas vide if (chambre.getText().toString() != null && chambre.getText().toString().trim().length() > 0) { // On recupere la valeur de l'EditText //namePlayer1 = name1.getText().toString(); return false; } return true; } }); parkInt = (EditText) findViewById(R.id.park_int_edit); parkInt.setOnEditorActionListener(new OnEditorActionListener () { public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { // Si le champ n'est pas vide if (parkInt.getText().toString() != null && parkInt.getText().toString().trim().length() > 0) { // On recupere la valeur de l'EditText //namePlayer1 = name1.getText().toString(); return false; } return true; } }); parkExt = (EditText) findViewById(R.id.park_ext_edit); parkExt.setOnEditorActionListener(new OnEditorActionListener () { public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { // Si le champ n'est pas vide if (parkExt.getText().toString() != null && parkExt.getText().toString().trim().length() > 0) { // On recupere la valeur de l'EditText //namePlayer1 = name1.getText().toString(); return false; } return true; } }); sdb = (EditText) findViewById(R.id.sdb_edit); sdb.setOnEditorActionListener(new OnEditorActionListener () { public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { // Si le champ n'est pas vide if (sdb.getText().toString() != null && sdb.getText().toString().trim().length() > 0) { // On recupere la valeur de l'EditText //namePlayer1 = name1.getText().toString(); return false; } return true; } }); sd = (EditText) findViewById(R.id.sd_edit); sd.setOnEditorActionListener(new OnEditorActionListener () { public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { // Si le champ n'est pas vide if (sd.getText().toString() != null && sd.getText().toString().trim().length() > 0) { // On recupere la valeur de l'EditText //namePlayer1 = name1.getText().toString(); return false; } return true; } }); chRDC = (EditText) findViewById(R.id.ch_rdc_edit); chRDC.setOnEditorActionListener(new OnEditorActionListener () { public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { // Si le champ n'est pas vide if (chRDC.getText().toString() != null && chRDC.getText().toString().trim().length() > 0) { // On recupere la valeur de l'EditText //namePlayer1 = name1.getText().toString(); return false; } return true; } }); etage = (EditText) findViewById(R.id.etage_edit); etage.setOnEditorActionListener(new OnEditorActionListener () { public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { // Si le champ n'est pas vide if (etage.getText().toString() != null && etage.getText().toString().trim().length() > 0) { // On recupere la valeur de l'EditText //namePlayer1 = name1.getText().toString(); return false; } return true; } }); // Ecoute des CheckBox plainPied = (CheckBox) findViewById(R.id.check_box_plain_pied); plainPied.setOnClickListener(new CheckBox.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub if (plainPied.isChecked()) { // On save les info } else { // On save pas } } }); surSousSol = (CheckBox) findViewById(R.id.check_box_sur_sous_sol); surSousSol.setOnClickListener(new CheckBox.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub if (plainPied.isChecked()) { // On save les info } else { // On save pas } } }); // Ecoute des GridView table1 = (GridView) findViewById(R.id.liste_cuisine); elements1 = getResources().getStringArray(R.array.liste_cui); ArrayAdapter<String> adaptateur1 = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_multiple_choice); for (int i=0; i < elements1.length; i++) { adaptateur1.add(elements1[i]); } table1.setAdapter(adaptateur1); // Ajout du listener sur la grid table1.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View v, int position, long id) { Toast.makeText(MainActivity.this, "L'element selectionne est >"+elements1[position]+"<", Toast.LENGTH_SHORT).show(); } }); table2 = (GridView) findViewById(R.id.liste_chauff); elements2 = getResources().getStringArray(R.array.liste_type_chauff); ArrayAdapter<String> adaptateur2 = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_multiple_choice); for (int i=0; i < elements2.length; i++) { adaptateur2.add(elements2[i]); } table2.setAdapter(adaptateur2); table2.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View v, int position, long id) { Toast.makeText(MainActivity.this, "L'element selectionne est >"+elements2[position]+"<", Toast.LENGTH_SHORT).show(); } }); // Creation du spinner spinner = (Spinner) findViewById(R.id.spinner_nat_chauff); // Create an ArrayAdapter using the string array and a default spinner layout ArrayAdapter<CharSequence> adapterSpinner = ArrayAdapter.createFromResource(this, R.array.liste_nat_chauff, android.R.layout.simple_spinner_item); // Specify the layout to use when the list of choices appears adapterSpinner.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // Apply the adapter to the spinner spinner.setAdapter(adapterSpinner); // Test d'ecoute du spinner spinner.setOnItemSelectedListener(new OnItemSelectedListener () { public void onItemSelected(AdapterView<?> arg0, View v, int pos, long row) { // Recuperation de la valeur selectionnee //Object itemnom1 = arg0.getItemAtPosition(pos); //sexe1 = String.valueOf(itemnom1); } public void onNothingSelected(AdapterView<?> arg0) { } }); // Ecoute du bouton save save = (Button) findViewById(R.id.buttonSaveIntBien); save.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { clickSave(); } }); } public void clickSave(){ Toast.makeText(MainActivity.this, "La sauvegarde se realise.", Toast.LENGTH_SHORT).show(); } }
Mon premier problème se trouve dans les "LinearLayout" qui englobent mes TextView et EditText.
Dans mon code, je position le TextView à "5dp" du bord gauche et l'EditText à "25dp" du bord droit. Or, lors de l'execution de mon programme, seul le positionnement du TextView est pris en compte.
J'ai essayé de remplacerpar
Code : Sélectionner tout - Visualiser dans une fenêtre à part android:layout_marginRight="25dp"
mais rien n'y fait...
Code : Sélectionner tout - Visualiser dans une fenêtre à part android:marginRight="25dp"
Quelqu'un aurait une idée ?
Mon deuxième problème se trouve dans les GridView.
Ma première GridView comprend 5 éléments et ma deuxième 10.
Le problème que j'ai est le suivant: Lors de l’exécution de mon programme, mes GridView ne m'affichent pas l’intégralité de mes éléments.
En effet, mes deux GridView m'affichent qu'une seule ligne avec deux éléments.
Quelqu'un aurait une idée pour faire afficher afficher l’intégralité de mes éléments dans la GridView ?
Je vous remercie d'avance pour votre aide et j'attends avec impatience vos retours !
Partager