开发者

Don't allow negative value from button press

开发者 https://www.devze.com 2023-03-10 16:58 出处:网络
Good afternoon, I have searched around for this answer, but because I am not exactly sure how to ask it, I am having a hard time finding an answer that fits my needs.I was working on a golf score car

Good afternoon,

I have searched around for this answer, but because I am not exactly sure how to ask it, I am having a hard time finding an answer that fits my needs. I was working on a golf score card tutorial, which I have completed, however, now I am looking to continue on with the application and make it even better.

Right now for each hole I have a score value with a "+" button and a "-" button, and when you hit that button it either does score--; or score++;

case R.id.buttonMinus:
    score--;
    textScore.setText(String.valueOf(score));
    break;
case R.id.buttonPlus:
    score++;
    textScore.setText(String.valueOf(score));
    break;

What I am wondering i开发者_Go百科s how do I not allow "score" to be less than 0?

I would like users to be able to go up and down, but not less than 0.

Any help would be greatly appreciated!

Thanks!

Rob


Is this what you want?

case R.id.buttonMinus:
    if (score > 0)
        score--;
    textScore.setText(String.valueOf(score));
    break;
0

精彩评论

暂无评论...
验证码 换一张
取 消