有没有一种方法来触发一个事件时,一个EditText视图的内容发生了变化? [英] Is there a way to fire an event when the contents of an EditText view have changed?
问题描述
我可以看到在设备火键特定查看
与 onKey
,但这不火当软件键盘
上的按键是pressed。
I can see keys on the device fire for a particular View
with onKey
, but this doesn't fire when keys on the software keyboard
are pressed.
我试图构建一个动态 UI
的重新计算的值作为输入的变化,而它的变化。
I am trying to build a dynamic UI
that recalculates a value as the input changes, while it's changing.
有没有一种方法来捕捉,要么价值的的EditText
有哪些变化?
Is there a way to capture either that the value of the EditText
has changed?
推荐答案
是的,你只需要添加一个TextChangedListener:
Yeah, you just need to add a TextChangedListener:
textEdit.addTextChangedListener(new TextWatcher(){
@Override
public void afterTextChanged(Editable editable)
{
// Do Stuff
}
@Override
public void beforeTextChanged(CharSequence text, int start, int count, int after)
{
// Do Stuff
}
@Override
public void onTextChanged(CharSequence arg0, int start, int before, int count)
{
// Do Stuff
}
});
您可以在这里找到更多的信息:
You can find more info here:
<一个href="http://developer.android.com/intl/de/reference/android/text/TextWatcher.html">http://developer.android.com/intl/de/reference/android/text/TextWatcher.html
这篇关于有没有一种方法来触发一个事件时,一个EditText视图的内容发生了变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!