0

I want an EditText to lose focus the moment the user touches other UI elements in the Activity like check boxes or really touches anywhere outside the EditText within the Activity, but this is not happening. The focus only gets changed when the user starts typing into another EditText. Not for example when they click on an Checkbox or when they click on other areas of the screen.

Code Droid
  • 9,864
  • 16
  • 69
  • 111
  • Possible duplicate of http://stackoverflow.com/questions/1109022/how-to-close-hide-the-android-soft-keyboard?rq=1?. If this doesn't help, can you make your question more specific? – Kyle Clegg Jul 06 '12 at 21:12
  • Its not a duplicate. This is a slightly different than keyboard question, although it does sound similar. In this case the keyboard will go away when you take some other action, but the problem is the EditText does not lose focus. Because it does not loose focus I cannot change the input method at the point I would like. – Code Droid Jul 06 '12 at 21:18

2 Answers2

2

It sounds like you need to add the following two lines to all of the widgets in your layout:

android:focusable="true"
android:focusableInTouchMode="true"

That way they can all receive focus (normally only certain ones can) and you can attach onFocusChangeListener to the EditText in question and you should achieve the desired results.

Of course, this could also play havoc with your other widgets (not knowing what they are I can't be certain), but it's worth a shot.

Barak
  • 16,117
  • 9
  • 49
  • 84
-1

Could you not just force close the android soft keyboard on click event of another View?

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);

The toggle call literally does just that - if its open, it will close, if its closed, it will open!

RenegadeAndy
  • 4,849
  • 14
  • 58
  • 115
  • This is not about the keyboard. But its similar. It really about how to detect make the EditText loose focus. When the keyboard is gone the EditText still has the focus. – Code Droid Jul 06 '12 at 21:14
  • Say when keyboard shuts give something else a requestFocus call then? – RenegadeAndy Jul 06 '12 at 21:17
  • How can I detech when keyboard shuts? – Code Droid Jul 06 '12 at 21:19
  • and know that it just detached from that EditBox? – Code Droid Jul 06 '12 at 21:20
  • Perhaps you are right that it is about the keyboard in a sense, but I need to know how to detect the close of the keyboard and know that it is closing from that particular EditText as there are others? Please update your answer. – Code Droid Jul 06 '12 at 21:22
  • What I am trying to do is change the TransformationMethod at this point to obfuscate. So I need a hook into this moment. – Code Droid Jul 06 '12 at 21:23