Bonjour à tous,
Je suis confrontée à un problème que je n'arrive pas à résoudre. J'y ai passé plusieurs jours mais rien à faire, je ne comprends pas comme faire.
J'ai une activité avec un Edittext "Rubrique", deux radiobuttons "C" et "P" et deux boutons "Ajouter une rubrique" et "Ajouter une sous-rubrique".
Le clique sur le bouton "Ajouter une rubrique" entraine l'ajout de l'EditText, des deux radiobuttons, des deux boutons plus un autre bouton "Tout supprimer".
Le clique sur sur le bouton "Ajouter une sous-rubrique" entraine l'ajout d'un EditText "Sous-rubrique", d"un bouton "ajouter une sous-rubrique", "ajouter une sous-sous-rubrique" et "supprimer".
Le clique sur sur le bouton "Ajouter une sous-sous-rubrique" entraine l'ajout d'un EditText "Sous-sous-rubrique", d"un bouton "ajouter une sous-sous-rubrique" et "supprimer".
Voilà le problème :
1. Lorsque je clique sur "tout supprimer" cela devrait supprimer la rubrique et ses sous-rubrique, voire ses sous-sous-rubriques, mais actuellement ca ne supprime que la rubrique concernée.
2. Si j'ai, par exemple, trois rubriques, et que je clique sur ajouter une rubrique au niveau de la 1ère rubrique, je souhaiterais que l'edittext ajouté s'ajoute en dessous du premier, alors qu'actuellement il sera en dessous du 3ième.
EcatalogueActivity4.java :
activity_ecatalogue4.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
57
58
59
60
61
62
63 public class EcatalogueActivity4 extends Activity { public Button btnSuivant, btnPrecedent; public EditText rubrique; public RadioButton c, p; Button btnAdd; ImageButton btnAdd2, btnAdd3; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_ecatalogue4); btnAdd = (Button) findViewById(R.id.btnAdd); btnAdd2 = (ImageButton) findViewById(R.id.btnAdd2); btnAdd3 = (ImageButton) findViewById(R.id.btnAdd3); View b = findViewById(R.id.btnAdd3); b.setVisibility(View.GONE); btnSuivant = (Button) findViewById(R.id.btnSuivant); RubriqueDynamiqueEcommerce.add(this, btnAdd); RubriqueDynamiqueEcommerce.add2(this, btnAdd2); RubriqueDynamiqueEcommerce.add3(this, btnAdd3); btnPrecedent = (Button) findViewById(R.id.btnPrecedent); rubrique = (EditText) findViewById(R.id.rubrique); c = (RadioButton) findViewById(R.id.c); p = (RadioButton) findViewById(R.id.p); // Bouton "Suivant" et ses conditions pour passer à la deuxième activité btnSuivant.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { int len1 = rubrique.length(); if(len1==0) { Toast.makeText(getApplicationContext(), "Veuillez entrer une rubrique", Toast.LENGTH_LONG).show(); } else if (!c.isChecked() && !p.isChecked()) { Toast.makeText(getApplicationContext(), "Veuillez choisir le type de la rubrique", Toast.LENGTH_LONG).show(); } else { // Bouton "Précédent", retour à l'activité précédente Intent intent = new Intent(EcatalogueActivity4.this, EcatalogueActivity5.class); startActivity(intent); } } }); // Bouton "Précédent", retour à l'activité précédente btnPrecedent.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onBackPressed(); } }); } }
RubriqueDynamiqueEcommerce.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 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".LoginActivity"> <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_alignParentTop="true" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:id="@+id/linearTeste" android:weightSum="1"> <TextView android:id="@+id/rubriques" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="20dip" android:text="Rubriques" android:gravity="center" android:textSize="30dip" android:textColor="#006FB7"/> <TableLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:stretchColumns="1"> <TableRow> <TextView android:id="@+id/legende" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Légende :" android:textSize="20sp" android:layout_marginTop="40dip"/> <TextView android:id="@+id/cms" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="C signifie CMS" android:inputType="text" android:padding="10dp" android:textSize="20sp" android:layout_marginTop="40dip" android:layout_column="1" android:layout_marginLeft="50sp"/> </TableRow> <TableRow android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:id="@+id/categorie" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="P signifie Catégorie de produits" android:inputType="text" android:padding="10dp" android:textSize="20sp" android:layout_marginTop="10dip" android:layout_column="1" android:layout_marginLeft="50sp"/> </TableRow> </TableLayout> <TableRow android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="right" android:weightSum="1"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="C" android:textSize="20sp" android:layout_marginTop="20sp" android:layout_marginLeft="710sp" android:id="@+id/textView" android:layout_weight="0.02" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="P" android:textSize="20sp" android:layout_marginTop="20sp" android:layout_marginLeft="28sp" android:id="@+id/textView2" /> </TableRow> <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:shrinkColumns="*" android:stretchColumns="*" android:id="@+id/tablelayout2"> <TableRow android:layout_height="wrap_content" android:layout_width="fill_parent" android:gravity="center_horizontal"> <EditText android:id="@+id/rubrique" android:layout_width="600sp" android:layout_height="wrap_content" android:hint="Rubrique *" android:textSize="20sp" android:background="#ffffff" android:textColor="#222222" android:textColorHint="#999999" android:padding="10sp" android:layout_marginTop="20sp" android:layout_weight="0.14" /> <RadioGroup android:id="@+id/radioGenderGroup1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/c" android:textSize="20sp" android:layout_marginTop="22sp" android:layout_marginLeft="60sp" android:checked="false" /> <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/p" android:textSize="20sp" android:layout_marginLeft="10sp" android:layout_marginTop="22sp" android:checked="false" /> </RadioGroup> <Button android:id="@+id/btnAdd" android:layout_width="100dip" android:layout_height="50dip" android:layout_marginTop="20dip" android:layout_marginLeft="25sp" android:background="#006FB7" android:text="Ajouter" android:textColor="#ffffff"/> <ImageButton android:id="@+id/btnAdd2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:layout_marginTop="20dip" android:layout_marginLeft="25sp" android:src="@android:drawable/ic_input_add" /> <ImageButton android:id="@+id/btnAdd3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:layout_marginTop="20dip" android:visibility="gone" android:layout_marginLeft="25sp" android:src="@android:drawable/ic_menu_add" /> </TableRow> </TableLayout> <ScrollView android:id="@+id/scrollView1" android:layout_width="match_parent" android:layout_height="fill_parent"> <LinearLayout android:id="@+id/linearLayoutForm" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> </LinearLayout> </ScrollView> <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:shrinkColumns="*" android:stretchColumns="*" android:id="@+id/tablelayout"> <TableRow android:layout_height="wrap_content" android:layout_width="fill_parent" android:gravity="center_horizontal"> <Button android:id="@+id/btnPrecedent" android:layout_width="300dip" android:layout_height="45dip" android:layout_marginTop="40dip" android:textColor="#ffffff" android:background="#006FB7" android:text="Précédent"/> <Button android:id="@+id/btnSuivant" android:layout_width="300dip" android:layout_height="45dip" android:layout_marginTop="40dip" android:layout_marginLeft="80sp" android:textColor="#ffffff" android:background="#006FB7" android:text="Suivant"/> </TableRow> </TableLayout> <Button android:id="@+id/btnEnregistrer" android:layout_width="300dip" android:layout_height="45dip" android:layout_marginTop="40dip" android:textColor="#ffffff" android:background="#006FB7" android:text="Enregistrer" android:layout_gravity="center"/> </LinearLayout> </RelativeLayout> </ScrollView>
ajout_rubrique_ecommerce.cml :
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 public class RubriqueDynamiqueEcommerce { public static void add(final Activity activity, Button btn) { // On définit le Linear Layout d'origine final LinearLayout linearLayoutForm = (LinearLayout) activity.findViewById(R.id.linearLayoutForm); // Lors du clique sur le bouton "Ajouter", des EditTexts "Rubrique" apparaissent dynamiquement btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // On définit le Linear Layout a ajouté lors de l'ajout dynamique final LinearLayout newView = (LinearLayout)activity.getLayoutInflater().inflate(R.layout.ajout_rubrique_ecommerce, null); newView.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); RadioButton c = (RadioButton) newView.findViewById(R.id.c); RadioButton p = (RadioButton) newView.findViewById(R.id.p); Button btnAdd_rubrique = (Button) newView.findViewById(R.id.btnAdd_rubrique); ImageButton btnAdd2 = (ImageButton) newView.findViewById(R.id.btnAdd2); ImageButton btnAdd3 = (ImageButton) newView.findViewById(R.id.btnAdd3); ImageButton btnDelete = (ImageButton) newView.findViewById(R.id.btnDelete); Button btnSuivant = (Button) newView.findViewById(R.id.btnSuivant); EditText rubrique = (EditText) newView.findViewById(R.id.rubrique); RubriqueDynamiqueEcommerce.add(activity , btnAdd_rubrique); RubriqueDynamiqueEcommerce.add2(activity, btnAdd2); RubriqueDynamiqueEcommerce.add3(activity, btnAdd3); // Lors du clique sur l'image bouton croix, la rubrique dynamiquement ajoutée se supprime btnDelete.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder alertDialog = new AlertDialog.Builder(activity); alertDialog.setTitle("Suppresion"); alertDialog.setMessage("Voulez-vous vraiment supprimer la rubrique et ses sous-rubriques ?"); alertDialog.setIcon(android.R.drawable.ic_menu_delete); alertDialog.setPositiveButton("Oui", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog,int which) { linearLayoutForm.removeView(newView); } }); alertDialog.setNegativeButton("Non", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); alertDialog.show(); } }); linearLayoutForm.addView(newView); } }); } public static void add2(final Activity activity, final ImageButton btn) { // On définit le Linear Layout d'origine final LinearLayout linearLayoutForm = (LinearLayout) activity.findViewById(R.id.linearLayoutForm); // Lors du clique sur l'image bouton plus, des EditTexts "Sous-rubrique" apparaissent dynamiquement btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // On définit le Linear Layout a ajouté lors de l'ajout dynamique final LinearLayout newView = (LinearLayout)activity.getLayoutInflater().inflate(R.layout.ajout_sous_rubrique_ecommerce, null); newView.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); final ImageButton btnRemove = (ImageButton) newView.findViewById(R.id.btnRemove); final ImageButton btnAdd2 = (ImageButton) newView.findViewById(R.id.btnAdd2); final ImageButton btnAdd3 = (ImageButton) newView.findViewById(R.id.btnAdd3); RubriqueDynamiqueEcommerce.add2(activity, btnAdd2); RubriqueDynamiqueEcommerce.add3(activity, btnAdd3); btnAdd3.setVisibility(View.VISIBLE); // Lors du clique sur l'image bouton croix, la sous-rubrique dynamiquement ajoutée se supprime btnRemove.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { linearLayoutForm.removeView(newView); } }); linearLayoutForm.addView(newView); } }); } public static void add3(final Activity activity, final ImageButton btn) { // On définit le Linear Layout d'origine final LinearLayout linearLayoutForm = (LinearLayout) activity.findViewById(R.id.linearLayoutForm); // Lors du clique sur l'image bouton plus, des EditTexts "Sous-rubrique" apparaissent dynamiquement btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // On définit le Linear Layout a ajouté lors de l'ajout dynamique final LinearLayout newView = (LinearLayout)activity.getLayoutInflater().inflate(R.layout.ajout_sous_sous_rubrique_ecommerce, null); newView.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); final ImageButton btnRemove2 = (ImageButton) newView.findViewById(R.id.btnRemove2); final ImageButton btnAdd3 = (ImageButton) newView.findViewById(R.id.btnAdd3); RubriqueDynamiqueEcommerce.add3(activity, btnAdd3); // Lors du clique sur l'image bouton croix, la sous-rubrique dynamiquement ajoutée se supprime btnRemove2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { linearLayoutForm.removeView(newView); } }); linearLayoutForm.addView(newView); } }); } }
ajout_sous_rubrique_ecommerce.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
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 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/ajout_rubrique_vitrine" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal"> <EditText android:id="@+id/rubrique" android:layout_width="640sp" android:layout_height="wrap_content" android:hint="Rubrique" android:textSize="20sp" android:background="#ffffff" android:textColor="#222222" android:textColorHint="#999999" android:padding="10sp" android:layout_marginTop="20sp" android:layout_weight="0.14"> <requestFocus /> </EditText> <RadioGroup android:id="@+id/radioGenderGroup1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal"> <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/c" android:textSize="20sp" android:layout_marginTop="25sp" android:layout_marginLeft="60sp" android:checked="false" /> <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/p" android:textSize="20sp" android:layout_marginLeft="10sp" android:layout_marginTop="25sp" android:checked="false" /> </RadioGroup> <Button android:id="@+id/btnAdd_rubrique" android:layout_width="100dip" android:layout_height="50dip" android:layout_marginTop="20dip" android:layout_marginLeft="65sp" android:background="#006FB7" android:text="Ajouter" android:textColor="#ffffff"/> <ImageButton android:id="@+id/btnAdd2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:layout_marginTop="20dip" android:layout_marginLeft="25sp" android:src="@android:drawable/ic_input_add" /> <ImageButton android:id="@+id/btnAdd3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:layout_marginTop="20dip" android:visibility="gone" android:layout_marginLeft="25sp" android:src="@android:drawable/ic_menu_add" /> <ImageButton android:id="@+id/btnDelete" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:layout_marginTop="20dip" android:layout_marginLeft="25sp" android:src="@android:drawable/ic_menu_delete" /> </LinearLayout>
ajout_sous_sous_rubrique_ecommerce.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 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/ajout_sous_rubrique_ecommerce" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal"> <EditText android:layout_width="350sp" android:layout_height="wrap_content" android:id="@+id/sous_rubrique" android:hint="Sous-rubriques" android:textSize="20sp" android:layout_marginLeft="50sp" android:background="#ffffff" android:textColor="#222222" android:textColorHint="#999999" android:padding="10sp" android:layout_marginTop="20sp" android:layout_weight="0.14" /> <ImageButton android:id="@+id/btnAdd2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:layout_marginTop="20dip" android:layout_marginLeft="25sp" android:src="@android:drawable/ic_input_add" /> <ImageButton android:id="@+id/btnAdd3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:layout_marginTop="20dip" android:layout_marginLeft="25sp" android:src="@android:drawable/ic_menu_add" /> <ImageButton android:id="@+id/btnRemove" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:layout_marginTop="20dip" android:layout_marginLeft="25sp" android:src="@android:drawable/ic_delete" /> </LinearLayout>
Je ne sais pas si cela est possible. J'ai tourné le problème dans tous les sens. Mais si quelqu'un peut m'aider, j'accepte avec plaisir.
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 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/ajout_sous_sous_rubrique_ecommerce" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal"> <EditText android:layout_width="350sp" android:layout_height="wrap_content" android:id="@+id/sous_rubrique" android:hint="Sous-rubriques" android:textSize="20sp" android:layout_marginLeft="100sp" android:background="#ffffff" android:textColor="#222222" android:textColorHint="#999999" android:padding="10sp" android:layout_marginTop="20sp" android:layout_weight="0.14" /> <ImageButton android:id="@+id/btnAdd3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:layout_marginTop="20dip" android:layout_marginLeft="25sp" android:src="@android:drawable/ic_menu_add" /> <ImageButton android:id="@+id/btnRemove2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:layout_marginTop="20dip" android:layout_marginLeft="25sp" android:src="@android:drawable/ic_delete" /> </LinearLayout>
Partager