I'm very new to Android programming so please forgive me if this is a stupid query.
I have an Edittext for a password field, and a button to submit the password. I also have a couple of Textviews which are hidden (shows if password is correct/incorrect), which I'd like to turn visible using an if/else statement.
When I run the code (on an AVD), nothing happens when I click the submit button. At all, ever.
I know this is probably really simple, but looking at other answers on questions similar to this was no help, I've been trying for days to figure out what I'm doing wrong...
..So ANY help would be really really appreciated. Thank you!! :D
-I use Eclipse, and Android 4.2.2
Here's the Java part:
final TextView success = (TextView) findViewById(R.id.textView1);
final TextView failure = (TextView) findViewById(R.id.textView2);
Button firstButton = (Button)findViewById(R.id.button1);
final EditText userPassword = (EditText)findViewById(R.id.passwordField);
firstButton.setOnClickListener(
new View.OnClickListener(){
public void onClick(View v){
if(userPassword.getText().toString() == "pa$$word"){
success.setVisibility(View.VISIBLE);
}
else{
failure.setVisibility(View.VISIBLE);
}
}
});
XML:
<Button android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/button"
android:layout_marginBottom="75dp"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:id="@+id/button1"/>
<EditText android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_centerHorizontal="true"
android:id="@+id/passwordField"
android:inputType="textPassword"
android:ems="10"
android:layout_above="@+id/button1">
<requestFocus/>
</EditText>
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@+string/pwCorrect"
android:layout_marginBottom="124dp"
android:layout_centerHorizontal="true"
android:id="@+id/textView1"
android:layout_above="@+id/passwordField"
android:visibility="gone"/>
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@+string/pwIncorrect"
android:layout_centerHorizontal="true"
android:id="@+id/textView2"
android:visibility="gone"
android:layout_centerVertical="true"/>