jeudi 23 juin 2016

If statement to check if variable is equal to a string - Java [duplicate]

This question already has an answer here:

This is a quiz app in Java. I am trying to compare the answer text stored as a variable (answeredOne) to the actual answer Prophase. I cannot get them to be equal. Do you see anything wrong with this code?

    EditText questionOne = (EditText) findViewById(R.id.answer_one);
    String answeredOne = questionOne.getText().toString();
    if (answeredOne == "Prophase") {
        score = score + 1;
    }

I keep getting zero when answering in the question.

Aucun commentaire:

Enregistrer un commentaire