我的应用程序中现在有两个 textView。一个 textView 用作 Counter,其他服务器用作 Limit。我想要完成的是当计数器等于限制时,计数器设置回零并且限制增加 100。
private int i = 0;
Spinner spinnerMonsters = (Spinner) findViewById(R.id.spinnerMonsters);
TextView textViewBattleResults = (TextView) findViewById(R.id.textViewBattleResults);
TextView textViewXPValue = (TextView) findViewById(R.id.textViewXPValue);
TextView textViewXpNextLevel = (TextView) findViewById(R.id.textViewXpNextLevel);
if (textViewXPValue.getText().toString().equals(textViewXpNextLevel.getText().toString())) {
int newLimit = Integer.parseInt(textViewXpNextLevel.getText().toString()) + 100;
textViewXpNextLevel.setText(newLimit + "");
textViewXPValue.setText("0");
}
else {
textViewXPValue.setText(textViewXPValue.getText().toString());
textViewXpNextLevel.getText().toString();
}
//Monster sequences
if (spinnerMonsters.getSelectedItem().toString().equals("(0) Training Dummy")) {
textViewBattleResults.setText("You have killed Training Dummy for 10 experience points!");
i = i+10;
textViewXPValue.setText(String.valueOf(i));
}
else {
textViewBattleResults.setText(" ");
textViewXPValue.setText(textViewXPValue.getText().toString());
}
if (spinnerMonsters.getSelectedItem().toString().equals("(2) Cockroach")) {
textViewBattleResults.setText("You have killed a Cockroach for 27 experience points!");
i = i+27;
textViewXPValue.setText(String.valueOf(i));
}
else {
textViewBattleResults.setText(" ");
textViewXPValue.setText(textViewXPValue.getText().toString());
}
}
});
这里的问题是当点击按钮时计数器会增加十。但是当 Counter 等于 Limit 时,Limit 增加 100,并且 Counter 保持相同的数字并且不会重置为零。
有什么建议么..?
编辑
另外,如果计数器等于或大于限制,我将如何做同样的事情?