android - 如何检查 EditText 是否已更改?

标签 android android-edittext

我需要知道 EditText 是否被更改,而不是用户是否在字段中输入了一些文本,而只需要知道 String 是否被更改。

最佳答案

你需要一个 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) {

  }
}

关于android - 如何检查 EditText 是否已更改?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7391891/

相关文章:

java - 如何在所有 Activity 中显示一个 fragment

java - 在屏幕中平滑移动按钮 - Android

android - Kotlin 集合在 Android 上抛出 ClassNotFoundException

android - 将 Android EditText 格式化为特定模式

android - 如何将文本设置为对话框中的 Edittext?

Android - onContextItemSelected 中的 AlertDialog 不起作用

php - 如何从 API 服务器删除特定的推送通知

android - EditText 显示 2 行文本,而不是 1 行,尽管设置了所有属性(仅在 Galax Tab 10.1,ICS 上)

android - Android 编辑文本中的美元符号

android - '安卓 :paddingRight’ working with ‘android:drawableRight’