Android (Lollipop) EditText onFocus fired multiple times

纵饮孤独 提交于 2019-12-10 06:18:16

问题


I have a couple of EditTexts with onFocusChangeListeners

// When the field gains or loses focus
txtMinimumValue.setOnFocusChangeListener(new View.OnFocusChangeListener() {
    @Override
    public void onFocusChange(View view, boolean hasFocus) {
        editFocusChange(view, hasFocus);
    }
});

I'm not having any issues on pre-Lollipop devices, but any Nexus 5's and the onFocusChange is fired about 7 times.

I found this SO: Custom ListAdapter consisting of EditText lose focus called twice

and then I found this Android Open Source Issue that looks related: https://code.google.com/p/android/issues/detail?id=80180 A Project Member said, "The framework version does this too. Fixed for a future release." Anyway to know when appcompat-v7:21.0.3 is released and I can test if this fixes my issue?

Anyone having this same issue?


回答1:


I have numerous filter screens where I might have several views on top and edit boxes, and then a list of values in a ListView. I've been dynamically building the bottom list view of values from arrays, and then programmatically building the top section of views and adding this top section as a header view. This is so the entire screen scrolls together, b/c you shouldn't add a ListView to a ScrollView.

Any EditText views on the top section might have onFocusChange methods to adjust the filter values manually entered. On Lollipop, there must be a bug where these programmatically built views added as a ListView header don't work, b/c the onFocusChange methods were firing repeatedly. I had to build the top as an xml for the onFocusChange methods to fire correctly.



来源:https://stackoverflow.com/questions/27370105/android-lollipop-edittext-onfocus-fired-multiple-times

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!