Im trying to compare the values of two edittext boxes. What i would like is to just compare passw1 = passw2. As my code is now comparing two strings i have entered as i could not get to compare them.
final EditText passw1= (EditText) findViewById(R.id.passw1);
final EditText passw2= (EditText) findViewById(R.id.passw2);
Button buttoks = (Button) findViewById(R.id.Ok);
buttoks.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (passw1.toString().equalsIgnoreCase("1234") && passw2.toString().equalsIgnoreCase("1234")){
Toast.makeText(getApplication(),"Username and password match", Toast.LENGTH_SHORT).show();
}
else {
Toast.makeText(getApplication(),"Username and password doesn't match", Toast.LENGTH_SHORT).show();
}
} });
[EDIT]
I made a mistake earlier, because, to get the text, you need to use .getText().toString().
Here is a full working example:
Original answer (Will not work because of the lack of toString())
Try using .getText() instead of .toString().
.toString() returns a String representation of the whole object, meaning it won’t return the text you entered in the field (see for yourself by adding a Toast which will show the output of .toString())