Android: 如何追踪键盘使用

huangapple go评论74阅读模式
英文:

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) {  
                
            }  
        });

huangapple
  • 本文由 发表于 2020年7月28日 21:43:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/63135566.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定