Android : onFocusChange is not working for me

on Wednesday, July 30, 2014


I want to disappear the keyboard when the focus goes out of the TextEdit box. I have throughly searched stackoverflow and google for an answer and have tried every single response/article I have seen but nothing seems to work for me.


As many, I am very new to Android development. I must be overlooking some minor detail to no avail.


My current implementation (again, I have tried many solutions) is as follows:


My class implements OnFocusChangeListener. OnCreate after calling super and setContentView I do:


EditText editText = (EditText) findViewById(R.id.text_box);

editText.setOnFocusChangeListener(this);


and


@Override public void onFocusChange(View v, boolean hasFocus) { Log.d(TAG, "--> onFocusChange"); }


But I never see that Log message.


Sometimes I think that onFocusChange is not what I think it is. My idea is that when we touch the textedit field this view gets the focus, and when you touch any other area of the screen, say a button/listbox/etc the textedit losses the focus and onFocusChange should be called, but it is not, I never see the log entry.


Any ideas what I can be missing here?


I would really appreciate your comments.


0 comments:

Post a Comment