final EditText et1 = (EditText)findViewById(R.id.et1);
et1.setOnFocusChangeListener(new OnFocusChangeListener(){
@Override
public void onFocusChange(View v, boolean hasFocus) {
if ( hasFocus )
{
et1.setTextColor(0xFF000000);
if ( et1.getText().equals("Email") ) { et1.setText(""); }
}
else
{
et1.setTextColor(0xFF7F7F7F);
if ( et1.getText().equals("") ) { et1.setText("Email"); }
}
}
});
et1 has "Email" in it by default. When the user clicks on it, I want it to clear.
The OnFocusChangeListener works fine as the color changes, but the text does not change, i.e. the
if ( et1.getText().equals("Email") )
doesn't fire. Nor does the equals(""), after I clear the et.
What am I doing wrong?
Try comparing et1.getText().toString().equals("Email") instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With