我需要计算点击次数并显示点击次数,textView2
而我的代码只显示数字 4。我使用了一个 while 循环来检查点击次数。
public void Clicks(View v){
final TextView answerLabel = (TextView)findViewById(R.id.textView1); //show text from answer variable.
TextView count = (TextView) findViewById(R.id.textView2); //display click count.
String answer = null;
int i = 0;
while(i < 5){ // I allow user click just 5 time.
switch (v.getId()){
case R.id.button1 :
answer= "ROCK";
answerLabel.setText(answer);
count.setText(String.valueOf(i));
i++;
break;
case R.id.button2 :
answer = "SCISSOR";
answerLabel.setText(answer);
count.setText(String.valueOf(i));
i++;
break;
case R.id.button3 :
answer = "PAPER";
answerLabel.setText(answer);
count.setText(String.valueOf(i));
i++;
break;
}
}
}
如何正确显示?