My code:
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?
et1.getText()is obviously not returning "Email". The compiler is not broken, break out your debugger and see exactly what it is returning. EDIT: Ninja'd by an evil bag of candy...