문제

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

도움이 되었습니까?

해결책

use the equals method from String to compare strings

if (ChPassword1.equals(ChPassword2)) {
}

== compares strings reference

다른 팁

Better use

ChPassword1.equals(ChPassword2)

Use equals for String matching

if(ChPassword1.equals(ChPassword2)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top