This TextView
has two functions. Firstly, it can switch the password between two status, HIDE and SHOW. Then it change the TextView
text between "SHOW" and "HIDE".
The first function can work perfectly. But the second didn't work very well. Whenever I open my app. The first click on the TextView
, It only change the password status, but not the TextView
text. Unless I click multiple times, both function would be work.
After several test, I found only the TextView
text can not work when I clicked the widget at the very first time. I am a noob on Android Studio, so I think this might be just a simple question. Are there anyone can tell me why this happened, please! Thank you!
TVtoggle.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (TVtoggle.getText() == "SHOW") {
ETpassword.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
ETpassword.setSelection(ETpassword.length());
TVtoggle.setText("HIDE");
}
else {
TVtoggle.setText("SHOW");
ETpassword.setInputType(InputType.TYPE_CLASS_TEXT |
InputType.TYPE_TEXT_VARIATION_PASSWORD);
ETpassword.setSelection(ETpassword.length());
}
}
});