Bonjour,
Je souhaite affiché plusieurs Alertdialog les unes à la suite des autres suivant un nombre que j'aurai rentré. Cependant, avec mon code actuelle j'ai deux soucis : la première Alert à s'afficher est la dernière, et lorsque j'appui sur "OK" pour confirmer mes données rentré l'application se ferme.
Le code :
Pourriez-vous m'aider ?
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 package com.example.convertisseurpuissance; import android.app.Activity; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.widget.EditText; import android.widget.ImageView; public class OptionActivity extends Activity implements OnClickListener{ final Context context = this; int z = 1; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_options); final ImageView retour = (ImageView) findViewById(R.id.retour); final ImageView validepalier = (ImageView) findViewById(R.id.validepalier); final ImageView validetm = (ImageView) findViewById(R.id.validetm); retour.setOnClickListener(this); validepalier.setOnClickListener(this); validetm.setOnClickListener(this); } public void onClick(View v) { EditText palier = (EditText) findViewById(R.id.palier); String pl = palier.getText().toString(); int paliers = Integer.parseInt(pl); Intent intent = new Intent(); switch (v.getId()){ case R.id.retour: intent = new Intent(OptionActivity.this, MainActivity.class); startActivity(intent); break; case R.id.validepalier: for(z=1;z<=paliers;z++){ //Layout en tant que view LayoutInflater factory = LayoutInflater.from(this); final View alertDialogView = factory.inflate(R.layout.alertdialogperso,null); //Creation de l'alertdialog AlertDialog.Builder adb = new AlertDialog.Builder(this); //Affectation de la vue perso à l'alertdialog adb.setView(alertDialogView); //Titre AlertDialog adb.setTitle("Level "+z); //Icone adb.setIcon(android.R.drawable.ic_dialog_alert); //bouton OK adb.setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { EditText puissance = (EditText) alertDialogView.findViewById(R.id.puissanceval); EditText temps = (EditText) alertDialogView.findViewById(R.id.tempsval); if(z==1){ EditText ppalier = (EditText) findViewById(R.id.ppalier1); EditText tpalier = (EditText) findViewById(R.id.tpalier1); ppalier.setText(puissance.getText().toString()); tpalier.setText(temps.getText().toString()); }else if(z==2){ EditText ppalier = (EditText) findViewById(R.id.ppalier2); EditText tpalier = (EditText) findViewById(R.id.tpalier2); ppalier.setText(puissance.getText().toString()); tpalier.setText(temps.getText().toString()); }else if(z==3){ EditText ppalier = (EditText) findViewById(R.id.ppalier3); EditText tpalier = (EditText) findViewById(R.id.tpalier3); ppalier.setText(puissance.getText().toString()); tpalier.setText(temps.getText().toString()); }else if(z==4){ EditText ppalier = (EditText) findViewById(R.id.ppalier4); EditText tpalier = (EditText) findViewById(R.id.tpalier4); ppalier.setText(puissance.getText().toString()); tpalier.setText(temps.getText().toString()); }else if(z==5){ EditText ppalier = (EditText) findViewById(R.id.ppalier5); EditText tpalier = (EditText) findViewById(R.id.tpalier5); ppalier.setText(puissance.getText().toString()); tpalier.setText(temps.getText().toString()); }else if(z==6){ EditText ppalier = (EditText) findViewById(R.id.ppalier6); EditText tpalier = (EditText) findViewById(R.id.tpalier6); ppalier.setText(puissance.getText().toString()); tpalier.setText(temps.getText().toString()); }else if(z==7){ EditText ppalier = (EditText) findViewById(R.id.ppalier7); EditText tpalier = (EditText) findViewById(R.id.tpalier7); ppalier.setText(puissance.getText().toString()); tpalier.setText(temps.getText().toString()); }else if(z==8){ EditText ppalier = (EditText) findViewById(R.id.ppalier8); EditText tpalier = (EditText) findViewById(R.id.tpalier8); ppalier.setText(puissance.getText().toString()); tpalier.setText(temps.getText().toString()); } } }); adb.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { finish(); } }); adb.show(); } break; case R.id.validetm: EditText tm = (EditText) findViewById(R.id.tm); break; } } }
Merci d'avance.
Partager