I have two textViews in my app right now. One textView serves as a Counter and the other servers as the Limit. What I want to accomplish is when the Counter equals the Limit, the Counter is set back to ZERO and the Limit is increased by 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());
}
}
});
The problem here is that the counter will count up by ten when the button is clicked. But when the Counter equals the Limit, the Limit increases by 100 and the Counter remains at the same number and doesn’t reset back to ZERO.
Any suggestions..?
EDIT
Also, how would i do the same thing but if the Counter was Equal to or Greater than the Limit?
You don’t reset value of i to zero. You first set text of xpvalue to zero, but then you set it’s text to current value ofi, which is not zero.