Salut, j'ai un problème, j'ai trois activités, la première pour récupérer les noms des joueurs, ensuite on appuie sur le bouton pour arriver sur la deuxième activité qui est le tableau des scores puis la troisième pour rentrer les données d'une partie Le problème est qu'au lieu de mettre le score dans les textview dédiés, il le met dans celles des noms des joueurs et donc c'est embêtant, voici le code :
MainActivity.java:activity.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 package com.example.tarot; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; // Notre activité détectera les touchers et les clics sur les vues qui se sont inscrites public class MainActivity extends Activity { //Variables final String tableauChaine[] = {"0","0","0","0","0"}; final String TableauChaine2[] = {"0","0","0","0","0"}; Button button1; String Joueur1; String Joueur2; String Joueur3; String Joueur4; String Joueur5; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //Pour garder dans l'activité 2 les variables //On récupère tous les éléments de notre interface graphique grâce aux ID button1 = (Button) findViewById(R.id.button1); //On attribue un écouteur d'évènement à tous les boutons button1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { button1Click(); } private void button1Click() { //Ce qui se produit au clic sur le bouton //Lancement Activite 2 Intent intent = new Intent(MainActivity.this, activity2.class); EditText t1 = (EditText) findViewById(R.id.editText1); EditText t2 = (EditText) findViewById(R.id.editText2); EditText t3 = (EditText) findViewById(R.id.editText3); EditText t4 = (EditText) findViewById(R.id.editText4); EditText t5 = (EditText) findViewById(R.id.editText5); final String[] TableauChaine1 = new String[] {t1.getText().toString(), t2.getText().toString(), t3.getText().toString(), t4.getText().toString(),t5.getText().toString()}; intent.putExtra("com.example.tarot", TableauChaine1); startActivity(intent); } }); } }activity3.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 package com.example.tarot; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; //Definir activité 2 public class activity2 extends Activity { //Variables String Joueur1; String Joueur2; String Joueur3; String Joueur4; String Joueur5; Integer Score1 ; Integer Score2 ; Integer Score3 ; Integer Score4 ; Integer Score5 ; //On recupere les variables @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity2); //On récupère tous les éléments de notre interface graphique grâce aux ID Button button2; button2 = (Button) findViewById(R.id.button2); //On attribue un écouteur d'évènement à tous les boutons button2.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { button1Click(); } private void button1Click() { //Ce qui se produit au clic sur le bouton Intent intent2 = new Intent(activity2.this, activity3.class); final String[] TableauChaine2 = new String[] {Joueur1,Joueur2,Joueur3,Joueur4,Joueur5}; intent2.putExtra("com.example.tarot", TableauChaine2); startActivity(intent2); } }); Intent intent = getIntent(); if (intent != null) { final String[] stringArray = intent.getStringArrayExtra("com.example.tarot"); TextView t11 = (TextView) findViewById(R.id.editText11); t11.setText(stringArray[0]); Joueur1 = stringArray[0]; TextView t12 = (TextView)findViewById(R.id.editText12);; t12.setText(stringArray[1]); Joueur2 = stringArray[1]; TextView t13 = (TextView) findViewById(R.id.editText13); t13.setText(stringArray[2]); Joueur3 = stringArray[2]; TextView t14 = (TextView) findViewById(R.id.editText14); t14.setText(stringArray[3]); Joueur4 = stringArray[3]; TextView t15 = (TextView) findViewById(R.id.editText15); t15.setText(stringArray[4]); Joueur5 = stringArray[4]; } } public void onStart(Bundle savedInstanceState) { super.onStart(); setContentView(R.layout.activity2); Intent intent4 = getIntent(); if (intent4 != null) { final String[] stringArray2 = intent4.getStringArrayExtra("com.example.tarot"); Score1 = Score1 + Integer.parseInt(stringArray2[0]); Score2 = Score2 + Integer.parseInt(stringArray2[1]); Score3 = Score3 + Integer.parseInt(stringArray2[2]); Score4 = Score4 + Integer.parseInt(stringArray2[3]); Score5 = Score5 + Integer.parseInt(stringArray2[4]); TextView t6 = (TextView) findViewById(R.id.editText16); t6.setText( String.valueOf(Score1)); TextView t7 = (TextView) findViewById(R.id.editText17); t7.setText( String.valueOf(Score2)); TextView t8 = (TextView) findViewById(R.id.editText18); t8.setText(String.valueOf(Score3)); TextView t9 = (TextView) findViewById(R.id.editText19); t9.setText(String.valueOf(Score4)); TextView t10 = (TextView) findViewById(R.id.editText20); t10.setText(String.valueOf(Score5)); } } }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
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 package com.example.tarot; import java.util.ArrayList; import java.util.List; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.CheckBox; import android.widget.EditText; import android.widget.RadioButton; import android.widget.Spinner; public class activity3 extends Activity { //Variables RadioButton Check0; RadioButton Check1; RadioButton Check2; RadioButton Check3; Button Button3; Spinner spin; Spinner spin2; Spinner spin3; EditText Edit1; String Joueur1=null; String Joueur2=null; String Joueur3=null; String Joueur4=null; String Joueur5=null; Integer Total=0; Integer Contrat = 0; Integer GeneralScore=0; Integer Score1 = 0; Integer Score2 = 0; Integer Score3 = 0; Integer Score4 = 0; Integer Score5 = 0; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity3); spin=(Spinner) findViewById(R.id.spinner1); //Reception nom des joueurs Intent intent2 = getIntent(); if (intent2 != null) { final String[] stringArray = intent2.getStringArrayExtra("com.example.tarot"); Joueur1=stringArray[0]; Joueur2=stringArray[1]; Joueur3=stringArray[2]; Joueur4=stringArray[3]; Joueur5=stringArray[4]; //Création d'une liste d'élément à mettre dans le Spinner(pour l'exemple) List<String> exemple = new ArrayList<String>(); exemple.add(Joueur1); exemple.add(Joueur2); exemple.add(Joueur3); exemple.add(Joueur4); exemple.add(Joueur5); List<String> exemple2 = new ArrayList<String>(); exemple2.add("Petite (x1)"); exemple2.add("Garde (x2)"); exemple2.add("Garde sans (x4)"); exemple2.add("Garde contre (x6)"); /*Le Spinner a besoin d'un adapter pour sa presentation alors on lui passe le context(this) et un fichier de presentation par défaut( android.R.layout.simple_spinner_item) Avec la liste des elements (exemple) */ ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, exemple); /* On definit une présentation du spinner quand il est déroulé (android.R.layout.simple_spinner_dropdown_item) */ adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); //Enfin on passe l'adapter au Spinner et c'est tout spin.setAdapter(adapter); spin2=(Spinner) findViewById(R.id.spinner2); spin2.setAdapter(adapter); spin3=(Spinner) findViewById(R.id.spinner3); adapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, exemple2); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spin3.setAdapter(adapter); } //Click du bouton Button3 = (Button) findViewById(R.id.button3); //On attribue un écouteur d'évènement à tous les boutons Button3.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { button3Click(); } private void button3Click() { //Ce qui se produit au clic sur le bouton //Reinitialisation Score Score1=null; Score2=null; Score3=null; Score4=null; Score5=null; // Points à faire Edit1=(EditText) findViewById(R.id.Edittext6); Contrat = Integer.parseInt(Edit1.getText().toString()); Check0=(RadioButton) findViewById(R.id.radio0); Check1=(RadioButton) findViewById(R.id.radio1); Check2=(RadioButton) findViewById(R.id.radio2); Check3=(RadioButton) findViewById(R.id.radio3); boolean check0=Check0.isChecked(); boolean check1=Check1.isChecked(); boolean check2=Check2.isChecked(); boolean check3=Check3.isChecked(); if (check0) { Total=56; } if (check1) { Total=51; } if (check2) { Total=41; } if (check3) { Total=36; } //Points generaux GeneralScore = ((25 + (Contrat -Total))^2)^(1/2); if (spin3.getSelectedItem().toString().equals("Petite (x1)")) GeneralScore = GeneralScore * 1; if (spin3.getSelectedItem().toString().equals("Garde (x2)")) GeneralScore = GeneralScore * 2; if (spin3.getSelectedItem().toString().equals("Garde sans (x4)")) GeneralScore = GeneralScore * 4; if (spin3.getSelectedItem().toString().equals("Garde contre (x6)")) GeneralScore = GeneralScore * 6; // Si le contrat est réussi if (Contrat>=Total) { // Points preneur if (spin.getSelectedItem().toString().equals(Joueur1)) Score1= GeneralScore * 2; if (spin.getSelectedItem().toString().equals(Joueur2)) Score2= GeneralScore * 2; if (spin.getSelectedItem().toString().equals(Joueur3)) Score3= GeneralScore * 2; if (spin.getSelectedItem().toString().equals(Joueur4)) Score4= GeneralScore * 2; if (spin.getSelectedItem().toString().equals(Joueur5)) Score5= GeneralScore * 2; //Points Appelé if (spin2.getSelectedItem().toString().equals(Joueur1)) Score1= GeneralScore ; if (spin2.getSelectedItem().toString().equals(Joueur2)) Score2= GeneralScore ; if (spin2.getSelectedItem().toString().equals(Joueur3)) Score3= GeneralScore ; if (spin2.getSelectedItem().toString().equals(Joueur4)) Score4= GeneralScore ; if (spin2.getSelectedItem().toString().equals(Joueur5)) Score5= GeneralScore ; //Points Defenseurs if (Score1 == null) Score1= -1 * GeneralScore ; if (Score2 == null) Score2= -1 * GeneralScore ; if (Score3 == null) Score3= -1 * GeneralScore ; if (Score4 == null) Score4= -1 * GeneralScore ; if (Score5 == null) Score5= -1 * GeneralScore ; } // Si le contrat n'est pas réussi else { // Points preneur if (spin.getSelectedItem().toString().equals(Joueur1)) Score1= GeneralScore * -2; if (spin.getSelectedItem().toString().equals(Joueur2)) Score2= GeneralScore * -2; if (spin.getSelectedItem().toString().equals(Joueur3)) Score3= GeneralScore * -2; if (spin.getSelectedItem().toString().equals(Joueur4)) Score4= GeneralScore * -2; if (spin.getSelectedItem().toString().equals(Joueur5)) Score5= GeneralScore * -2; //Points Appelé if (spin2.getSelectedItem().toString().equals(Joueur1)) Score1= -1 * GeneralScore ; if (spin2.getSelectedItem().toString().equals(Joueur2)) Score2= -1 * GeneralScore ; if (spin2.getSelectedItem().toString().equals(Joueur3)) Score3= -1 * GeneralScore ; if (spin2.getSelectedItem().toString().equals(Joueur4)) Score4= -1 * GeneralScore ; if (spin2.getSelectedItem().toString().equals(Joueur5)) Score5= -1 * GeneralScore ; //Points Defenseurs if (Score1 == null) Score1= 1 * GeneralScore ; if (Score2 == null) Score2= 1 * GeneralScore ; if (Score3 == null) Score3= 1 * GeneralScore ; if (Score4 == null) Score4= 1 * GeneralScore ; if (Score5 == null) Score5= 1 * GeneralScore ; } //Transfert des scores vers activité2 Intent intent4 = new Intent(activity3.this, activity2.class); final String[] TableauScores = new String[] {Score1.toString(), Score2.toString(), Score3.toString(), Score4.toString(), Score5.toString()}; intent4.putExtra("com.example.tarot", TableauScores); startActivity(intent4); } }); } }activity.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 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <EditText android:id="@+id/editText1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:inputType="text" android:ems="10" /> <EditText android:id="@+id/editText2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:inputType="text" android:ems="10" /> <EditText android:id="@+id/editText3" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:inputType="text" android:ems="10" /> <EditText android:id="@+id/editText4" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:inputType="text" android:ems="10" /> <EditText android:id="@+id/editText5" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:inputType="text" android:ems="10" /> <Button android:id="@+id/button1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="97dp" android:layout_weight="1" android:text="Lancer" /> </LinearLayout>activity3.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/RelativeLayout1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:id="@+id/editText11" android:layout_width="fill_parent" android:layout_height="30dp" android:layout_alignParentTop="true" android:layout_weight="1" android:gravity="center" android:ems="10" /> <TextView android:id="@+id/editText16" android:layout_below="@+id/editText11" android:layout_width="fill_parent" android:layout_height="30dp" android:layout_weight="1" android:gravity="center" android:ems="10" /> <TextView android:id="@+id/editText12" android:layout_below="@+id/editText16" android:layout_width="fill_parent" android:layout_height="30dp" android:layout_weight="1" android:gravity="center" android:ems="10" /> <TextView android:id="@+id/editText17" android:layout_width="fill_parent" android:layout_height="30dp" android:layout_below="@+id/editText12" android:gravity="center" android:layout_weight="1" android:ems="10" /> <TextView android:id="@+id/editText13" android:layout_below="@+id/editText17" android:layout_width="fill_parent" android:layout_height="30dp" android:layout_weight="1" android:gravity="center" android:ems="10" /> <TextView android:id="@+id/editText18" android:layout_width="fill_parent" android:layout_height="30dp" android:gravity="center" android:layout_below="@+id/editText13" android:layout_weight="1" android:ems="10" /> <TextView android:id="@+id/editText14" android:layout_below="@+id/editText18" android:layout_width="fill_parent" android:layout_height="30dp" android:layout_weight="1" android:gravity="center" android:ems="10" /> <TextView android:id="@+id/editText19" android:layout_width="fill_parent" android:layout_height="30dp" android:gravity="center" android:layout_below="@+id/editText14" android:layout_weight="1" android:ems="10" /> <TextView android:id="@+id/editText15" android:layout_below="@+id/editText19" android:layout_width="fill_parent" android:layout_height="30dp" android:layout_weight="1" android:gravity="center" android:ems="10" /> <TextView android:id="@+id/editText20" android:layout_width="fill_parent" android:layout_height="30dp" android:layout_below="@+id/editText15" android:gravity="center" android:layout_weight="1" android:ems="10" /> <Button android:id="@+id/button2" android:layout_width="fill_parent" android:layout_height="80dp" android:gravity="center" android:layout_below="@+id/editText20" android:layout_weight="1" android:text="Calculer les Points" /> </RelativeLayout>
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 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/RelativeLayout1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:id="@+id/Textview1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_weight="1" android:ems="10" android:gravity="center" android:text="Points obtenus:" /> <EditText android:id="@+id/Edittext6" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@+id/Textview1" android:layout_centerHorizontal="true" android:layout_weight="1" android:ems="10" android:gravity="center" android:text="40" /> <TextView android:id="@+id/Textview2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@+id/Edittext6" android:layout_weight="1" android:ems="10" android:gravity="center" android:text="Preneur:" /> <Spinner android:id="@+id/spinner1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@+id/Textview2" android:layout_marginRight="0dp" android:layout_marginTop="0dp" /> <TextView android:id="@+id/Textview3" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@+id/spinner1" android:layout_weight="1" android:ems="10" android:gravity="center" android:text="Appelé:" /> <Spinner android:id="@+id/spinner2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@+id/Textview3" android:layout_marginRight="0dp" android:layout_marginTop="0dp" /> <TextView android:id="@+id/Textview4" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@+id/spinner2" android:layout_weight="1" android:ems="10" android:gravity="center" android:text="Prise:" /> <Spinner android:id="@+id/spinner3" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@+id/Textview4" android:layout_marginRight="0dp" android:layout_marginTop="0dp" /> <TextView android:id="@+id/Textview5" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@+id/spinner3" android:layout_weight="1" android:ems="10" android:gravity="center" android:text="Nombre de bouts:" /> <Button android:id="@+id/button3" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_weight="1" android:text="Calculer les Points" /> <RadioGroup android:id="@+id/Radiogroup1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/Textview5" android:orientation="horizontal" > <RadioButton android:id="@+id/radio0" android:layout_width="70dp" android:layout_height="wrap_content" android:checked="true" android:text="0" /> <RadioButton android:id="@+id/radio1" android:layout_width="70dp" android:layout_height="wrap_content" android:text="1" /> <RadioButton android:id="@+id/radio2" android:layout_width="70dp" android:layout_height="wrap_content" android:text="2" /> <RadioButton android:id="@+id/radio3" android:layout_width="70dp" android:layout_height="wrap_content" android:text="3" /> </RadioGroup> </RelativeLayout>
Partager