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 !!

Était-ce utile?

La solution

use the equals method from String to compare strings

if (ChPassword1.equals(ChPassword2)) {
}

== compares strings reference

Autres conseils

Better use

ChPassword1.equals(ChPassword2)

Use equals for String matching

if(ChPassword1.equals(ChPassword2)
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top