ClearFocus () on empty editText not working in Android

I tried to remove focus from an empty editText, but it does not work correctly. I called clearFocus()on edittextand then set a breakpoint when calling the function onFocusChanged().

Here's what happened: onFocusChanged()called 4 times using focused parameter values false,true,false,true.

I thought I onFocusChanged()needed to be called only once (with focus = false)

Sorry for my bad english. Any help would be greatly appreciated. Thanks

+4
source share
2 answers

This is because yours EditTextis the first custom view.

From the documents ,

. "" , . , , , , , .

EditText, .

+10

xml

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

clearFocus ,

 mFragmentBase.editText.clearFocus();
 mFragmentBase.parentLayout.requestFocus();
0

Source: https://habr.com/ru/post/1656090/


All Articles