表达式显示在屏幕上,每次提交错误答案时都会显示提示。
这是我的onClick方法代码:
TextView setHints = (TextView) findViewById(R.id.hints);
// Get the Answer from your EditText
String answer = display.getText().toString();
setAnswer.setText(answer);
for(int i = 0; i < multiArray.length ; i++)
{
// if the answer is in position 1 of Array [i]
if(answer.equals(multiArray[i][1]))
{
// We have found the answer, Congratulate the User
displayAnswer.setTextColor(getResources().getColor(R.color.green));
displayAnswer.setText("CORRECT");
break;
}else{
// Tell them how bad they are since they can't solve simple equations!
displayAnswer.setTextColor(getResources().getColor(R.color.red));
displayAnswer.setText("INCORRECT");
for (int count = 0; count<5; count++){
if(Prefs.getHints(this)){
if (Integer.parseInt(answer) < Integer.parseInt(multiArray[random][1])){
setHints.setText("Greater");
break;
}
else{
setHints.setText("Less");
}
if (Integer.parseInt(answer) == Integer.parseInt(multiArray[random][1])){
setHints.setText("Hints");
break;
}
}
if (count > 5){
displayAnswer.setText("No Hints Left!");
break;
}
}
}
}
似乎无法正常工作的部分是:
if (count > 5){
displayAnswer.setText("No Hints Left!");
break;
}
我希望在单击提交按钮4次后显示displayAnswer.setText("No Hints Left!");
。当我运行我的应用程序时,我仍然可以在5次尝试后提交答案。我在这里失踪了什么?
答案 0 :(得分:1)
count
永远不会超过5
。它在for
循环的顶部声明,终止于4(< 5
)。您需要保留一个活动级别(类级别)变量,该变量将跟踪单击按钮的次数,而不是使用for循环。
答案 1 :(得分:0)
如果count = 5
,你的循环就会停止for(int count = 0; count&lt; 5 ...
但你的&#34;没有提示了!&#34;仅在计数&gt;时显示5。
如何改变两者:
for(int count = 0; count&lt; 4 ...
if(count&gt; = 4)