本文介绍了获取afterTextChanged事件可编辑的ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个扩展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.

SDK文档链接

希望帮助!

这篇关于获取afterTextChanged事件可编辑的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 17:35