Possible Duplicate:
How do I compare strings in Java?
why equals() method when we have == operator?
All I'm trying to do here is to compare a text that was entered in a text-field widget with a given string ("abc") and then set the button-text to either "wrong pass" or "pass ok". However, the button-text is always set to "wrong pass" even if I enter the correct "password". What am I doing wrong?
public class FullscreenActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_start);
final Button button = (Button) findViewById(R.id.button);
final EditText textedit = (EditText) findViewById(R.id.textedit);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (textedit.getText().toString() == "abc")
button.setText("pass ok"); // doesn't work
else
button.setText("wrong pass");
}
});
}
...