为什么EditText.setOnFocusChangeListener会多次触发?

时间:2015-01-09 10:55:52

标签: android android-edittext android-view

我在ListView中的一行中使用了EditText。没有代码以编程方式请求焦点。填充ListView时,没有任何EditText视图被聚焦。当我点击其中一个给它焦点时,这是日志输出:

Comments field focus changed. hasFocus=true
Comments field focus changed. hasFocus=false
Comments field focus changed. hasFocus=true

这是在运行Lollipop 5.01的Nexus 7和软键盘上。所有三行都与完全相同的EditText视图相关。

如果我在运行5.01的Nexus 5上运行相同的版本,我会看到这一点,这是我期望的行为:

Comments field focus changed. hasFocus=true

这是听众:

    commentsView.setOnFocusChangeListener(new OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            Timber.i("Comments field focus changed. hasFocus=" + hasFocus);
            }
        }
    });

您将从代码中看到,除了记录到Timber(logcat)之外,事件没有做任何事情。为什么视图会在N7上获得,然后再次失去并再次获得关注?我需要使用此事件来触发数据保存,这种行为会导致问题。

有什么想法吗?

0 个答案:

没有答案
相关问题