Question

I'm new android developer and i want to check is two Edit Text match with each other or not ,I want it for password change. here is my code [edited] :

String ChPassword1=ChangePassword1_Box.getText().toString();
            String ChPassword2=ChangePassword2_Box.getText().toString();        
        if(ChPassword1==ChPassword2){
            savePreferences("PASSWORD", ChPassword1);

            Toast msg = Toast.makeText(getBaseContext(),"رمز تغییر کرد", Toast.LENGTH_LONG);
             msg.show();

        }

but it doesn't work !!

Was it helpful?

Solution

use the equals method from String to compare strings

if (ChPassword1.equals(ChPassword2)) {
}

== compares strings reference

OTHER TIPS

Better use

ChPassword1.equals(ChPassword2)

Use equals for String matching

if(ChPassword1.equals(ChPassword2)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top