如何检查 EditText 是否已更改? [英] How to check if an EditText was changed or not?

查看:19
本文介绍了如何检查 EditText 是否已更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

在这里查看它的实际效果:

See it here in action:

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) {

  }
}

这篇关于如何检查 EditText 是否已更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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