我有一个 EditText。当我点击它时,它变得可聚焦。我将键入要输入到 EditText 中的输入文本。我想为 EditText 实现一个监听器,这样当我停止输入时,它应该自动将该文本保存到数据库中而不是有一个按钮。如何让 EditText 监听输入是否停止?
最佳答案
像这样尝试。
EditText et = (EditText)findViewById(R.id.editText);
Log.e("TextWatcherTest", "Set text xyz");
et.setText("xyz");
et.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) { }
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) { }
@Override
public void afterTextChanged(Editable s) {
Log.e("TextWatcherTest", "afterTextChanged:\t" +s.toString());
}
});
关于android - 为 EditText 实现 Text Watcher,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8699569/