问题描述
我有一个扩展TextWatcher检测的变化在某些EditTexts的活动,所以它实现了:
I have an Activity that extends TextWatcher to detect changes in certain EditTexts, so it implements:
public void afterTextChanged(Editable s)
我的问题是:如果有几个EditTexts与.addTextChangedListener(本)集,我怎么能区分哪一个改给出的afterTextChanged过程中的可编辑对象
My question is: If there are several EditTexts with .addTextChangedListener(this) set, how can I differentiate which one changed given the Editable object in the afterTextChanged procedure?
推荐答案
另一种选择,用较少的匿名内部类,是简单地检查目前主要集中查看
。 如果您的应用程序的 TextWatcher
由用户所做的更改完全取决于在打字,然后修改会发生在查看
具有当前焦点。呼叫 getCurrentFocus()
从活动中的任何位置
或窗口
将返回查看
的用户主要集中在。从在 TextWatcher
,这将几乎肯定是特定的EditText
实例。
Another option, with fewer anonymous inner classes, would be to simply inspect the currently focused View
. If your application for TextWatcher
hinges solely on changes made by the user while typing, then the changes will always occur in the View
that has current focus. Calling getCurrentFocus()
from anywhere inside of an Activity
or Window
will return the View
the user is focused on. From inside a TextWatcher
, this will almost assuredly be the specific EditText
instance.
希望帮助!
这篇关于获取afterTextChanged事件可编辑的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!