我试图在我的 android 应用程序中的 edittext 中记录击键次数,但我想不出办法来做到这一点。
我认为 TextWatcher 是实现这一目标的方法,但目前没有任何效果。我是一名新手 android 开发人员,因此非常感谢任何帮助。
mainTextBlock.addTextChangedListener(keyCounter);
...
TextWatcher keyCounter = new TextWatcher() {
public void afterTextChanged(Editable s) {
keyCount++;
TextView keystrokeCount = (TextView)findViewById(R.id.keystrokeCount);
keystrokeCount.setText(keyCount);
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
public void onTextChanged(CharSequence s, int start, int before,
int count) {
}
};
每次在主文本块中输入任何文本时,我都会感到力不从心。我试图计算击键,而不是编辑文本中的字符数,否则它会相当简单......
非常感谢!