1
nameInput.setOnEditorActionListener(new OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.????_?????_??????) {
Integer inputLength2 = nameInput.getText().length();
String realTimeText = inputLength2.toString();
textView1.setText("Number of Characters: " + realTimeText);
}
return false;
}
});
nameInput是EditText类型的对象。我想在TextView上实时显示从EditText创建的字符串的数量。原理很简单,在我看来它可以很好地工作(我所需要做的就是“截取”软键盘的字符,就像我在那里完成的那样),但问题是:Android:如何捕捉软键盘的每个触摸输入?
http://developer.android.com/reference/android/view/inputmethod/EditorInfo.html
没有常量可用于此,这可能意味着我需要做一些晦涩的技巧来解决问题。你知道我该怎么做吗?
非常感谢!谷歌的人很聪明;他们想到了一切:)。即使是名字“TextWatcher”也完全描述了我需要的东西。 – 2013-03-19 06:34:25