I was trying to create a little game, and it works like this: When you achieve 10 points, the next step is to achieve 20 points, but I cannot change the textview variable.
if(tv_score.getText().toString().equals("Score: "+10)){
tv_nextStep.setText("Next step: " + 10);
}
if(tv_score.getText().toString().equals("Score: "+20)){
tv_nextStep.setText("Next step: " + 30);
}
I was trying to get the score from the textview, and based on that, change the next step textview, but the value is always 0 (the default value).
the score is like this: When I click the button, the score goes to the textview (this part is working)
score = score + 1;
tv_score.setText("Score: " + score);
Im guessing this is what you want?
int score = 0;
btn.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
score = score + 1;
tv_score.setText("Score: " + score);
if(score == 10){
tv_nextStep.setText("Next step: " + 10);
}
if(score == 20){
tv_nextStep.setText("Next step: " + 30);
}
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.