У меня возникли трудности с запуском моей программы. gameloop()
вызывается в onCreate
. Затем у меня есть кнопка, которая вызывает questions()
. Просто хочу отобразить десять вопросов в текстовом виде и обновлять его каждый раз, когда нажата кнопка отправки. Любая помощь будет фантастической.Loop not Looping?
int i1 = Min + (int)(Math.random() * ((Max - Min) + 1));
int answer;
int q1 = random1 + random2;
int q2 = random1 - random2;
int q3 = random1/random2;
int q4 = random1 * random2;
Вышеупомянутые объявлены.
public void gameloop(){
for (int i = 0; i < 10; i++) {
if (i1 == 1) {
answer = q1;
editTextEquation.setText(random1 + "+" + random2);
continue;
}
if (i1 == 2) {
answer = q2;
editTextEquation.setText(random1 + "-" +random2);
continue;
}
if (i1 == 3) {
answer = q3;
editTextEquation.setText(random1 + "/" +random2);
continue;
}
if (i1 == 4) {
answer = q4;
editTextEquation.setText(random1 + "*" +random2);
continue;
}
}
}
public void questions() {
int score = 0;
int i = Integer.parseInt(editText.getText().toString());
if (i == answer) {
score ++;
editTextEquation.setText(random1 + "/" +random2);
gameloop();
}
else {
editTextEquation.setText(random1 + "*" +random2);
gameloop();
}
Какова ценность i1? – Sid
Что такое 'i1'? .setText (что-то) уничтожит все, что находится в editTextEquation. Если это ваш текст, вы напишете ему 10x, но будет только последняя запись –
Да, в соответствии с тем, что вы написали, 'i1' значение не изменяется во время цикла, поэтому почему цикл? – noMAD