Android事件时间监听器

时间:2012-10-05 02:13:57

标签: android

我想用SPen SDK的SPenTouchListener实现一个方法。听众工作正常但我会从用户的第一次触摸起每隔10ms捕获触摸数据(坐标等),因为用户按下另一个按钮。我怎么能这样做? 这是听众代码的一部分:

public boolean onTouchPen(View view, MotionEvent event) {
            updateTouchUI(event.getX(), event.getY(), event.getPressure(), event.getAction(), "Pen");
            }

private void updateTouchUI(float x, float y, float pressure, int action, String tool){
    mX.setText("X : " + String.format("%.2f", x));
    mY.setText("Y : " + String.format("%.2f", y));
    mPressure.setText("Pressure : " + String.format("%.3f", pressure)); 
}

换句话说,我想每隔10ms调用 updateTouchUI ,因为用户按下活动中的按钮。此外,我想每次都捕获时间戳。

1 个答案:

答案 0 :(得分:2)

您可以创建Handler

private Handler mHandler = new Handler();
public void updateUI() {
        mHandler.postDelayed(mUpdateTimeTask, 10); //10ms
    }  

    /**
     * Background Runnable thread
     * */
    private Runnable mUpdateTimeTask = new Runnable() {
           public void run() {
      updateTouchUI (param...); //Your function

               // Running this thread after 10 milliseconds
               mHandler.postDelayed(this, 10);
           }
    };

在您的欲望updateUI()

的onClickEvent中添加Button
相关问题