开发者

Setting the score on textview

I am trying to set the score in a game but it isn't doing anything at the moment.

I have declared a score variable:

    static int score = 0;

When an answer is shown in another textview as "Correct" I want the score to increment and show this in another textfield which will be for the score.

So far I have tried this:

  public void score(){
    check.getText();
if(check.equals("Correct")){
    score++;
    Score.setText(String.valueOf(score));

}

check is a Textfield which shows Correct or Incorrect. Score is another textfield. and then I put the method score() into an onclick, but this doesn't update the tex开发者_如何学编程tfield.

I would appreciate any advice on this.

Thanks

Edit:

Setting the score on textview


check.equals("Correct")

should be

check.getText().equals("Correct")


You don't heed the check.getText() method call that you have by itself. And you need to use this for your if statement

if(check.getText().toString().equals("correct))

getText returns the object type Editable which is not a String. If you are getting a force close please edit you question to include the stack trace from the LogCat output.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜