Reputation: 5
Im working on hebrew logo quiz app and i need to use an edittext that the user type what he see and then compare it to the preset value. The current code is
Check.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String word = String.valueOf(test.getText());
String word2 = String.valueOf("טקסט בעברית");
if (word==word2){
tv.setText("True");
}
else tv.setText("False");
}
});
and the output is always False as well as the correct answer.. I really need help here
Upvotes: 0
Views: 148
Reputation: 5220
you are comparing two object by their references and because they are not same, returned value is always false. you should compare their values not their reference. read more here
String
class in java has a method for comparison. you should use equals
method. read more here
Upvotes: 1