Please check the following code snippet from button's onClick event handler.
The if statement does not execute even though its TRUE (because of relational operators == and && maybe)... but works fine when string method( .contains() ) used as shown at the end.
EditText uname = (EditText)findViewById(2);
EditText pwd = (EditText)findViewById(3);
TextView msg = (TextView)findViewById(4);
String a = uname.getText().toString();
String b = pwd.getText().toString();
if(a==("afnan")&& b==("secret")){
msg.setText("abc");
}else {
msg.setText("xyz " + a + b); // concatenated a and b to see their values and they are same as in IF statement so why does ELSE always get executed but not IF?
}
Replacing relational operators with the following works fine but if statement gets true for "afnanaaaaa" since it does contain "afnan" but not EXACLTY contain "afnan":
if(a.contains("afnan")&& b.contains("secret")){
msg.setText("Welcome !!!");
}else if (a!= "afnan" && b!= "secret"){
msg.setText("xyz ");
}
HELP PLEASE !!!!!!!!!!