Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compare two edittext fields in android

In my application i got two edit boxes,one is editPassword and other is editConfirmpassword.i want to compare data between those two boxes that both values are equal and only if they are equal then only write data in sharedpref file.

like image 631
birring Avatar asked Feb 15 '23 06:02

birring


2 Answers

Try this:

EditText e1 = (EditText)findViewById(R.id.editPassword);
EditText e2 = (EditText)findViewById(R.id.editConfirmpassword);
if(e1.getText().toString().equals( e2.getText().toString())){
//do things if these 2 are correct.
}
like image 139
superuser Avatar answered Feb 17 '23 19:02

superuser


Use string comparison here. You can fetch the EditText value using getText().toString(); Now you can do a compare using compareToIgnoreCase

like image 25
prijupaul Avatar answered Feb 17 '23 21:02

prijupaul