In Java, two strings (and, in general, two objects) must be compared using equals() , not == . The == operator checks identity (this means: testing if two objects in memory are the same), while the equals() method checks two objects for equality (which means: testing if two objects have the same value), regardless of whether they are two different object. You are almost always interested in equality, not identity.
To fix your code, do the following:
String str = ((EditText)findViewById(R.id.editText1)).getText().toString(); boolean correct = "SampleText".equals(str);
Also note that it is recommended that you use the string literal first in the equals() call, so you are safe if the second string is null , avoiding a possible NullPointerException .
source share