英文:
Android : How to track Keyboard usage
问题
有没有办法追踪用户在软键盘上的输入速度?我想知道用户使用键盘的时间。希望我的问题清楚明了!
英文:
Is there a way to track how "fast" a user is on the soft keyboard? I want to konw the time the user takes when using the keyboard.
I hope my question is clear!
答案1
得分: 0
你可以在EditText中使用文本监听器(Text Watcher),在每次文本更改时计算时间差。
long initialTime = System.currentTimeMillis();
long total = 0;
editText.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence cs, int start, int before, int count) {
total = total + (System.currentTimeMillis() - initialTime);
initialTime = System.currentTimeMillis();
}
@Override
public void beforeTextChanged(CharSequence charSequence, int start, int count, int after) {
}
@Override
public void afterTextChanged(Editable editable) {
}
});
英文:
You could use a text watcher in the EditText and on every text change you can calculate the difference in time.
long intialTime=System.getCurrentTimeMillis();
long total = 0;
editText.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
total= total + (System.getCurrentTimeMillis()-initialTime)
intialTime = System.getCurrentTimeMillis();
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3)
{
}
@Override
public void afterTextChanged(Editable arg0) {
}
});
专注分享java语言的经验与见解,让所有开发者获益!
评论