Slaine82
Newbie
Hi All,
I am having a problem which is driving me crazy
, I am sure it is something simple but I just can't see what it wrong.
Basically I am having a problem with an if statement not being entered after using a equals statement even though both side match exactly, the code I have is
String currentQCorAns = correctAnswers[currentQNo];
//this pulls in an answer from an array in the resources value is "Hill Of Tara"
String currentSelectedString = (String)(selectedRadioButton.getText());
//this gets the current selected radio buttons text value is "Hill Of Tara"
if(currentQCorAns == currentSelectedString ){
Toast.makeText(mContext, "Question is correct", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(mContext, "Question is incorrect", Toast.LENGTH_SHORT).show();
}
I have tried everything from casting the variables to the same type to be sure. Even the following doesn't work:-
if(currentQCorAns == "Hill Of Tara")
It always enters the else part of the block. Can anyone help? Is it something to do with the fact I am pulling in the values from a resources file.
Thanks!
I am having a problem which is driving me crazy
, I am sure it is something simple but I just can't see what it wrong. Basically I am having a problem with an if statement not being entered after using a equals statement even though both side match exactly, the code I have is
String currentQCorAns = correctAnswers[currentQNo];
//this pulls in an answer from an array in the resources value is "Hill Of Tara"
String currentSelectedString = (String)(selectedRadioButton.getText());
//this gets the current selected radio buttons text value is "Hill Of Tara"
if(currentQCorAns == currentSelectedString ){
Toast.makeText(mContext, "Question is correct", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(mContext, "Question is incorrect", Toast.LENGTH_SHORT).show();
}
I have tried everything from casting the variables to the same type to be sure. Even the following doesn't work:-
if(currentQCorAns == "Hill Of Tara")
It always enters the else part of the block. Can anyone help? Is it something to do with the fact I am pulling in the values from a resources file.
Thanks!