I have a fairly simple question for you, regarding a getText().toString() method I'm using in an if statement.
Essentially, I'm asking the user a question. If they input the correct answer in the appropriate EditText, they move on to the next question. If not, they lose life. If their life is reduced to 0, they are sent back to the beginning of the game. If not, they must repeat the question. The problem I'm having while testing this is that after entering the correct answer, in this case "Atlantic", the method is executing as though the answer is wrong. Can anyone help with this?
PS I am aware that the Else If is redundant, it's just there for clarification purposes.
The code:
answerButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (answerText.getText().toString() == "Atlantic") {
KrakonQ2();
}
else if (answerText.getText().toString() != "Atlantic")
{
thePlayer.setPlayerHP(thePlayer.getPlayerHP() - 20);
if (thePlayer.getPlayerHP() <= 0)
{
thePlayer.setPlayerPos(0);
setupControls();
RoomText.setText(thedungeon[thePlayer.getPlayerPos()].getName());
setupDirectionButtons();
thePlayer.setPlayerHP(100);
}
else
{
KrakonQ1();
}
}
}
});