Almog Yanai
Almog Yanai

Reputation: 5

Android Hebrew EditText

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

Answers (1)

Mohammad Rahchamani
Mohammad Rahchamani

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

Related Questions