有没有一种方法来触发一个事件时,一个EditText视图的内容发生了变化?

问题描述:

我可以看到在设备火键特定查看 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:

http://developer.android.com/intl/de/reference/android/text/TextWatcher.html