0

I want to be able to detect when an edittext isn't clicked, so I can replace it with a textview. I tried

et.setOnFocusChangeListener(new OnFocusChangeListener() {    
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (!v.hasFocus()){
                    Toast.makeText(getApplicationContext(), "LOST FOCUS", Toast.LENGTH_SHORT).show();
                }
            }
        });

but the Toast message wouldn't get called.

Boken
  • 4,825
  • 10
  • 32
  • 42
NathanWick
  • 87
  • 1
  • 10

1 Answers1

1

You should use the boolean var that is supplied:

if (!hasFocus){

}

When you get the callback, it could be that the view still has focus, so v.hasFocus() might return true.

Boken
  • 4,825
  • 10
  • 32
  • 42
wvdz
  • 16,251
  • 4
  • 53
  • 90