如何获取是否在Android Activity中更改了textBox?

问题描述:

我有一个活动包含许多edittexts。我怎么知道用户是否有输入或更改edittext的内容?如何获取是否在Android Activity中更改了textBox?

不检查一个edittext,活动中有很多edittext。如果其中一个已被更改。当用户离开活动时,我需要告诉他/她,信息不会被保存。

+2

'addTextChangedListener'的链接。在这种情况下,请参考[this](http://developer.android.com/reference/android/widget/TextView.html#addTextChangedListener(android.text.TextWatcher)) – 2013-05-02 10:24:22

+0

textboxes是指textview还是editext? – Raghunandan 2013-05-02 10:28:30

+0

不检查一个edittext,活动中有很多edittext。如果其中一个已被更改。当用户离开活动时,我需要告诉他/她,信息不会被保存。 – 2013-05-03 00:58:23

我认为在这种情况下,文本框是指editext

使用文本观察家如下

EditText search= (EditText) findViewById(R.id.search); 
search.addTextChangedListener(new TextWatcher() { 

public void onTextChanged(CharSequence s, int start, int before, int count) { 
    // s is typed text  
} 

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

public void afterTextChanged(Editable s) { 
    } 
}); 

如果它的TextView检查以下

http://developer.android.com/reference/android/widget/TextView.html#addTextChangedListener(android.text.TextWatcher)