如何检查是否一个EditText已更改或不呢?或不、EditText

2023-09-06 02:20:54 作者:眼眸里的殇、无人能懂

我需要知道,如果一个的EditText 改变与否,不在于是否用户输入的领域的一些文字,但只有当字符串被改变。

I need to know if an EditText was changed or not, not whether or not the user inputted some text in the field, but only the if String was changed.

推荐答案

您需要 TextWatcher

在这里看到它在行动:

EditText text = (EditText) findViewById(R.id.YOUR_ID);
text.addTextChangedListener(textWatcher);


private TextWatcher textWatcher = new TextWatcher() {

  public void afterTextChanged(Editable s) {
  }

  public void beforeTextChanged(CharSequence s, int start, int count, int after) {
  }

  public void onTextChanged(CharSequence s, int start, int before,
          int count) {

  }
}