Java/Android programming/EditText – getText().toString()

Java/Android programming/EditText -> getText().toString() … here is a solution to the problem.

Java/Android programming/EditText -> getText().toString()

Possible Duplicate:
How do I compare strings in Java?

why equals() method when we have == operator ?

All I have to do here is compare the text entered in the text field widget to the given string (“abc”) and set the button text to “wrong pass” or “pass” line. However, even if I entered the correct “password”, the button text was always set to “wrong password”. What exactly 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");

}
    });
}

...

Related Problems and Solutions