如何在android中找到action up和action down事件之间的时间差距

vns*_*tty 0 events android gesture

我有以下代码......

public boolean onTouch(View view, MotionEvent me) {

    //here i want to know the  time of touch

    switch (me.getAction()) {
       case MotionEvent.ACTION_DOWN: { }  
       case MotionEvent.ACTION_UP: { }
       -
       -
       -
   }
  }
Run Code Online (Sandbox Code Playgroud)

任何的想法?

She*_*tib 7

这很简单

public yourClass{
    long down;    
    public boolean onTouch(View view, MotionEvent me) {
        //you don't need here the difference because it might be a down action!
        //you need the difference when the up action occurs
        switch (me.getAction()) {
            case MotionEvent.ACTION_DOWN:
                down = System.currentTimeMillis();
                break;
            case MotionEvent.ACTION_UP:
                //this is the time in milliseconds
                long diff = System.currentTimeMillis() - down; 
                break;
        }
    }
}     
Run Code Online (Sandbox Code Playgroud)