当前位置:   article > 正文

OnEditorActionListener回调两次问题_oneditoraction 回调两次

oneditoraction 回调两次

在Android14手机上发现的问题,详见代码

  1. Android12:
OnEditorActionListener { textView, actionId, event ->
		LogUtil.d("insertWord -- actionId:$actionId - event:${event?.action}")
        if (actionId == EditorInfo.IME_ACTION_SEARCH) {
            //自己的逻辑处理
        }
        false
}
打印:
searchEditorActionListener$lambda$11(line:370):insertWord -- actionId:3 - event:null
searchEditorActionListener$lambda$11(line:370):insertWord -- actionId:0 - event:0
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  1. Android14:
OnEditorActionListener { textView, actionId, event ->
		LogUtil.d("insertWord -- actionId:$actionId - event:${event?.action}")
        if (actionId == EditorInfo.IME_ACTION_SEARCH && event?.action != KeyEvent.ACTION_DOWN) {
            //自己的逻辑处理
        }
        false
}
打印:
earchEditorActionListener$lambda$11(line:371):insertWord -- actionId:3 - event:null
earchEditorActionListener$lambda$11(line:371):insertWord -- actionId:3 - event:0
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  1. 正确处理方式
OnEditorActionListener { textView, actionId, event ->
		LogUtil.d("insertWord -- actionId:$actionId - event:${event?.action}")
        if (actionId == EditorInfo.IME_ACTION_SEARCH && event?.action != KeyEvent.ACTION_DOWN) {
            //自己的逻辑处理
            true
        } else {
			false
		}
}
打印:
earchEditorActionListener$lambda$11(line:371):insertWord -- actionId:3 - event:null
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

注意Android12和Android14的打印结果是有差别的!
需要在OnEditorActionListener回调中处理是否消耗事件,自己消耗返回true,否则返回false。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/391071
推荐阅读
相关标签
  

闽ICP备14008679号