在afterTextChanged事件中获取可编辑的ID [英] Get Editable id in afterTextChanged event

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

问题描述

我有一个Activity可以扩展TextWatcher以检测某些EditText的更改,因此它实现了:

I have an Activity that extends TextWatcher to detect changes in certain EditTexts, so it implements:

public void afterTextChanged(Editable s)

我的问题是:如果有几个EditText与.addTextChangedListener(this)设置,我区分了在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?

推荐答案

另一个选项,更少的匿名内部类只需检查当前集中的 View 如果您的 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆